Code cleanup

- Use absolute paths for includes.
- Add file path to include guards.
- Use uint64_t for resource id.
- Compile engine code into separate lib.
- Compile time and run time string hashing functions.
- Rename Worker to ThreadPool.
- Update .gitignore
- Code generator for texture compressor.
This commit is contained in:
Attila Uygun 2021-10-27 14:19:10 +02:00
parent 042bffaff3
commit 0866349f58
115 changed files with 856 additions and 624 deletions

6
.gitignore vendored
View File

@ -1,8 +1,10 @@
build/android/.gradle
build/android/*.apk
build/android/app/.cxx
build/android/app/build
build/android/build
build/linux/gltest_x86_64_debug
build/linux/gltest_x86_64_release
build/linux/demo_x86_64_debug
build/linux/demo_x86_64_release
build/linux/obj
build/linux/woom
out

View File

@ -53,8 +53,8 @@ add_library(kaliber SHARED
../../../src/base/random.cc
../../../src/base/sinc_resampler.cc
../../../src/base/task_runner.cc
../../../src/base/thread_pool.cc
../../../src/base/timer.cc
../../../src/base/worker.cc
../../../src/demo/credits.cc
../../../src/demo/demo.cc
../../../src/demo/enemy.cc
@ -162,6 +162,7 @@ if (ANDROID_ABI STREQUAL arm64-v8a)
endif()
target_include_directories(kaliber PRIVATE
../../../src
${ANDROID_NDK}/sources/android/native_app_glue
)

View File

@ -8,6 +8,7 @@ config("compiler_defaults") {
cflags_cc = [
"-std=c++17",
"-I../../src",
]
}
}

View File

@ -1,13 +1,14 @@
.DEFAULT_GOAL := all
# --- Input variables ---
BUILD ?= release
ifeq ($(findstring $(BUILD),debug release),)
$(error BUILD must be set to debug or release)
endif
# Build all executables by default.
APPS ?= gltest
APPS ?= demo
# If the VERBOSE flag isn't set, then mute superfluous output.
ifeq ($(VERBOSE),)
@ -18,6 +19,7 @@ ifeq ($(VERBOSE),)
endif
# --- Internal variables ---
ARCH := $(shell uname -p)
SRC_ROOT := $(abspath ../../src)
OUTPUT_DIR := $(abspath .)
@ -51,7 +53,7 @@ endif
CFLAGS += -msse2
# Let C++ inherit all C flags.
CXXFLAGS = $(CFLAGS)
CXXFLAGS = $(CFLAGS) -I$(SRC_ROOT)
# Enable C++17
CXXFLAGS += -std=c++17
@ -65,28 +67,21 @@ CFLAGS += -DFALLBACK_CONFIG_DIRS='"/etc/xdg"'
CFLAGS += -DHAVE_SECURE_GETENV
# --- Internal functions ---
app_exe = $(OUTPUT_DIR)/$(1)_$(ARCH)_$(BUILD)
objs_from_src = $(patsubst $(SRC_ROOT)/%, $(BUILD_DIR)/%.o, $(basename $(1)))
objs_from_src_in = $(call objs_from_src, $(shell find $(1) -name "*.cc" -o -name "*.cpp" -o -name "*.c"))
# --- gltest application ---
ifneq ($(filter gltest,$(APPS)),)
# --- Engine ---
GLTEST_SRC := \
ENGINE_SRC := \
$(SRC_ROOT)/base/collusion_test.cc \
$(SRC_ROOT)/base/log.cc \
$(SRC_ROOT)/base/random.cc \
$(SRC_ROOT)/base/sinc_resampler.cc \
$(SRC_ROOT)/base/task_runner.cc \
$(SRC_ROOT)/base/thread_pool.cc \
$(SRC_ROOT)/base/timer.cc \
$(SRC_ROOT)/base/worker.cc \
$(SRC_ROOT)/demo/credits.cc \
$(SRC_ROOT)/demo/demo.cc \
$(SRC_ROOT)/demo/enemy.cc \
$(SRC_ROOT)/demo/hud.cc \
$(SRC_ROOT)/demo/menu.cc \
$(SRC_ROOT)/demo/player.cc \
$(SRC_ROOT)/demo/sky_quad.cc \
$(SRC_ROOT)/engine/animatable.cc \
$(SRC_ROOT)/engine/animator.cc \
$(SRC_ROOT)/engine/audio/audio_alsa.cc \
@ -179,16 +174,35 @@ GLTEST_SRC := \
$(SRC_ROOT)/third_party/vulkan/loader/unknown_ext_chain.c \
$(SRC_ROOT)/third_party/vulkan/loader/wsi.c
GLTEST_EXE := $(call app_exe,gltest)
GLTEST_OBJS := $(call objs_from_src, $(GLTEST_SRC))
EXES += $(GLTEST_EXE)
OBJS += $(GLTEST_OBJS)
ENGINE_LIB := $(BUILD_DIR)/libengine.a
ENGINE_OBJS := $(call objs_from_src, $(ENGINE_SRC))
LIBS += $(ENGINE_LIB)
OBJS += $(ENGINE_OBJS)
$(GLTEST_EXE): $(GLTEST_OBJS) $(LIBS)
$(ENGINE_LIB): $(ENGINE_OBJS)
# --- demo application ---
ifneq ($(filter demo,$(APPS)),)
DEMO_SRC := \
$(SRC_ROOT)/demo/credits.cc \
$(SRC_ROOT)/demo/demo.cc \
$(SRC_ROOT)/demo/enemy.cc \
$(SRC_ROOT)/demo/hud.cc \
$(SRC_ROOT)/demo/menu.cc \
$(SRC_ROOT)/demo/player.cc \
$(SRC_ROOT)/demo/sky_quad.cc
DEMO_EXE := $(call app_exe,demo)
DEMO_OBJS := $(call objs_from_src, $(DEMO_SRC))
EXES += $(DEMO_EXE)
OBJS += $(DEMO_OBJS)
$(DEMO_EXE): $(DEMO_OBJS) $(LIBS)
endif
# --- Build rules ---
# Dependencies.

View File

@ -16,11 +16,11 @@ source_set("base") {
"sinc_resampler.h",
"task_runner.cc",
"task_runner.h",
"thread_pool.cc",
"thread_pool.h",
"timer.cc",
"timer.h",
"vecmath.h",
"worker.cc",
"worker.h",
]
# ldflags = []

View File

@ -1,5 +1,5 @@
#ifndef CLOSURE_H
#define CLOSURE_H
#ifndef BASE_CLOSURE_H
#define BASE_CLOSURE_H
#include <functional>
#include <memory>
@ -56,4 +56,4 @@ std::function<ReturnType(Args...)> BindWeak(ReturnType (Class::*func)(Args...),
} // namespace base
#endif // CLOSURE_H
#endif // BASE_CLOSURE_H

View File

@ -1,4 +1,4 @@
#include "collusion_test.h"
#include "base/collusion_test.h"
#include <algorithm>
#include <cmath>

View File

@ -1,7 +1,7 @@
#ifndef COLLUSION_TEST_H
#define COLLUSION_TEST_H
#ifndef BASE_COLLUSION_TEST_H
#define BASE_COLLUSION_TEST_H
#include "vecmath.h"
#include "base/vecmath.h"
namespace base {
@ -20,4 +20,4 @@ bool Intersection(const Vector2f& center,
} // namespace base
#endif // COLLUSION_TEST_H
#endif // BASE_COLLUSION_TEST_H

View File

@ -1,5 +1,5 @@
#ifndef CONCURRENT_STACK_H
#define CONCURRENT_STACK_H
#ifndef BASE_CONCURRENT_STACK_H
#define BASE_CONCURRENT_STACK_H
#include <atomic>
#include <utility>
@ -88,4 +88,4 @@ class ConcurrentStack {
} // namespace base
#endif // CONCURRENT_STACK_H
#endif // BASE_CONCURRENT_STACK_H

View File

@ -1,5 +1,5 @@
#ifndef FILE_H
#define FILE_H
#ifndef BASE_FILE_H
#define BASE_FILE_H
#include <cstdio>
#include <memory>
@ -22,4 +22,4 @@ using ScopedFILE = std::unique_ptr<FILE, internal::ScopedFILECloser>;
} // namespace base
#endif // FILE_H
#endif // BASE_FILE_H

View File

@ -1,21 +1,28 @@
#ifndef HASH_H
#define HASH_H
#ifndef BASE_HASH_H
#define BASE_HASH_H
#include <stddef.h>
#define HHASH(x) base::HornerHash(31, x)
#include <string>
namespace base {
// Compile time string hashing function.
// Compile-time string hashing function.
template <size_t N>
constexpr inline size_t HornerHash(size_t prime,
const char (&str)[N],
size_t Len = N - 1) {
return (Len <= 1) ? str[0]
: (prime * HornerHash(prime, str, Len - 1) + str[Len - 1]);
constexpr inline size_t Hash(const char (&str)[N], size_t Len = N - 1) {
size_t hash_value = 0;
for (int i = 0; str[i] != '\0'; ++i)
hash_value = str[i] + 31 * hash_value;
return hash_value;
}
// The same hashing function for run-time.
inline size_t Hash(const std::string& str) {
size_t hash_value = 0;
for (std::string::value_type c : str)
hash_value = c + 31 * hash_value;
return hash_value;
}
} // namespace base
#endif // HASH_H
#endif // BASE_HASH_H

View File

@ -1,5 +1,5 @@
#ifndef INTERPOLATION_H
#define INTERPOLATION_H
#ifndef BASE_INTERPOLATION_H
#define BASE_INTERPOLATION_H
namespace base {
@ -40,4 +40,4 @@ inline float Acceleration(float t, float w) {
} // namespace base
#endif // INTERPOLATION_H
#endif // BASE_INTERPOLATION_H

View File

@ -1,4 +1,4 @@
#include "log.h"
#include "base/log.h"
#if defined(__ANDROID__)
#include <android/log.h>

View File

@ -1,5 +1,5 @@
#ifndef LOG_H
#define LOG_H
#ifndef BASE_LOG_H
#define BASE_LOG_H
#include <sstream>
@ -94,4 +94,4 @@ class LogAbort {
} // namespace base
#endif // LOG_H
#endif // BASE_LOG_H

View File

@ -1,5 +1,5 @@
#ifndef MEM_H
#define MEM_H
#ifndef BASE_MEM_H
#define BASE_MEM_H
#include <cstdlib>
#include <memory>
@ -8,7 +8,7 @@
#include <malloc.h>
#endif
#include "log.h"
#include "base/log.h"
#define ALIGN_MEM(alignment) __attribute__((aligned(alignment)))
@ -53,4 +53,4 @@ inline bool IsAligned(void* ptr) {
} // namespace base
#endif // MEM_H
#endif // BASE_MEM_H

View File

@ -1,5 +1,5 @@
#ifndef MISC_H
#define MISC_H
#ifndef BASE_MISC_H
#define BASE_MISC_H
#define CRASH *((int*)nullptr) = 0;
@ -31,4 +31,4 @@ inline int RoundUpToPow2(int val) {
} // namespace base
#endif // MISC_H
#endif // BASE_MISC_H

View File

@ -1,9 +1,9 @@
#include "random.h"
#include "base/random.h"
#include <limits>
#include "interpolation.h"
#include "log.h"
#include "base/interpolation.h"
#include "base/log.h"
namespace base {

View File

@ -1,5 +1,5 @@
#ifndef RANDOM_GENERATOR_H
#define RANDOM_GENERATOR_H
#ifndef BASE_RANDOM_H
#define BASE_RANDOM_H
#include <random>
@ -29,4 +29,4 @@ class Random {
} // namespace base
#endif // RANDOM_GENERATOR_H
#endif // BASE_RANDOM_H

View File

@ -1,10 +1,10 @@
#ifndef SEMAPHORE_H
#define SEMAPHORE_H
#ifndef BASE_SEMAPHORE_H
#define BASE_SEMAPHORE_H
#include <condition_variable>
#include <mutex>
#include "../base/log.h"
#include "base/log.h"
namespace base {
@ -38,4 +38,4 @@ class Semaphore {
} // namespace base
#endif // SEMAPHORE_H
#endif // BASE_SEMAPHORE_H

View File

@ -73,13 +73,13 @@
// Note: we're glossing over how the sub-sample handling works with
// |virtual_source_idx_|, etc.
#include "sinc_resampler.h"
#include "base/sinc_resampler.h"
#include <cmath>
#include <cstring>
#include <limits>
#include "log.h"
#include "base/log.h"
#if defined(_M_X64) || defined(__x86_64__) || defined(__i386__)
#include <xmmintrin.h>

View File

@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SINC_RESAMPLER_H_
#define SINC_RESAMPLER_H_
#ifndef BASE_SINC_RESAMPLER_H
#define BASE_SINC_RESAMPLER_H
#include <functional>
#include <memory>
#include "mem.h"
#include "base/mem.h"
namespace base {
@ -151,4 +151,4 @@ class SincResampler {
} // namespace base
#endif // SINC_RESAMPLER_H_
#endif // BASE_SINC_RESAMPLER_H

View File

@ -1,5 +1,5 @@
#ifndef SPINLOCK_H
#define SPINLOCK_H
#ifndef BASE_SPINLOCK_H
#define BASE_SPINLOCK_H
#include <atomic>
@ -39,4 +39,4 @@ class Spinlock {
} // namespace base
#endif // SPINLOCK_H
#endif // BASE_SPINLOCK_H

View File

@ -1,6 +1,6 @@
#include "task_runner.h"
#include "base/task_runner.h"
#include "log.h"
#include "base/log.h"
namespace {

View File

@ -1,5 +1,5 @@
#ifndef TASK_RUNNER_H
#define TASK_RUNNER_H
#ifndef BASE_TASK_RUNNER_H
#define BASE_TASK_RUNNER_H
#include <atomic>
#include <condition_variable>
@ -8,7 +8,7 @@
#include <mutex>
#include <tuple>
#include "closure.h"
#include "base/closure.h"
namespace base {
@ -85,4 +85,4 @@ class TaskRunner {
} // namespace base
#endif // TASK_RUNNER_H
#endif // BASE_TASK_RUNNER_H

View File

@ -1,22 +1,22 @@
#include "worker.h"
#include "base/thread_pool.h"
#include "log.h"
#include "base/log.h"
namespace base {
Worker* Worker::singleton = nullptr;
ThreadPool* ThreadPool::singleton = nullptr;
Worker::Worker() {
ThreadPool::ThreadPool() {
DCHECK(!singleton);
singleton = this;
}
Worker::~Worker() {
ThreadPool::~ThreadPool() {
Shutdown();
singleton = nullptr;
}
void Worker::Initialize(unsigned max_concurrency) {
void ThreadPool::Initialize(unsigned max_concurrency) {
if (max_concurrency > std::thread::hardware_concurrency() ||
max_concurrency == 0) {
max_concurrency = std::thread::hardware_concurrency();
@ -25,10 +25,10 @@ void Worker::Initialize(unsigned max_concurrency) {
}
while (max_concurrency--)
threads_.emplace_back(&Worker::WorkerMain, this);
threads_.emplace_back(&ThreadPool::WorkerMain, this);
}
void Worker::Shutdown() {
void ThreadPool::Shutdown() {
if (threads_.empty())
return;
@ -40,14 +40,14 @@ void Worker::Shutdown() {
threads_.clear();
}
void Worker::PostTask(const Location& from, Closure task) {
void ThreadPool::PostTask(const Location& from, Closure task) {
DCHECK((!threads_.empty()));
task_runner_.PostTask(from, std::move(task));
semaphore_.Release();
}
void Worker::PostTaskAndReply(const Location& from,
void ThreadPool::PostTaskAndReply(const Location& from,
Closure task,
Closure reply) {
DCHECK((!threads_.empty()));
@ -56,7 +56,7 @@ void Worker::PostTaskAndReply(const Location& from,
semaphore_.Release();
}
void Worker::WorkerMain() {
void ThreadPool::WorkerMain() {
for (;;) {
semaphore_.Acquire();

View File

@ -1,26 +1,26 @@
#ifndef THREAD_POOL_H
#define THREAD_POOL_H
#ifndef BASE_THREAD_POOL_H
#define BASE_THREAD_POOL_H
#include <atomic>
#include <thread>
#include <vector>
#include "closure.h"
#include "semaphore.h"
#include "task_runner.h"
#include "base/closure.h"
#include "base/semaphore.h"
#include "base/task_runner.h"
namespace base {
class TaskRunner;
// Feed the worker tasks (in the form of Closure objects) and they will be
// Feed the ThreadPool tasks (in the form of Closure objects) and they will be
// called on any thread from the pool.
class Worker {
class ThreadPool {
public:
Worker();
~Worker();
ThreadPool();
~ThreadPool();
static Worker& Get() { return *singleton; }
static ThreadPool& Get() { return *singleton; }
void Initialize(unsigned max_concurrency = 0);
@ -47,14 +47,14 @@ class Worker {
base::TaskRunner task_runner_;
static Worker* singleton;
static ThreadPool* singleton;
void WorkerMain();
Worker(Worker const&) = delete;
Worker& operator=(Worker const&) = delete;
ThreadPool(ThreadPool const&) = delete;
ThreadPool& operator=(ThreadPool const&) = delete;
};
} // namespace base
#endif // THREAD_POOL_H
#endif // BASE_THREAD_POOL_H

View File

@ -1,4 +1,4 @@
#include "timer.h"
#include "base/timer.h"
#include <thread>

View File

@ -1,5 +1,5 @@
#ifndef TIMER_H
#define TIMER_H
#ifndef BASE_TIMER_H
#define BASE_TIMER_H
#include <sys/time.h>
@ -28,4 +28,4 @@ class Timer {
} // namespace base
#endif // TIMER_H
#endif // BASE_TIMER_H

View File

@ -1,12 +1,12 @@
#ifndef VEC_MATH_H
#define VEC_MATH_H
#ifndef BASE_VEC_MATH_H
#define BASE_VEC_MATH_H
#include <cmath>
#include <string>
#include <utility>
#include "interpolation.h"
#include "log.h"
#include "base/interpolation.h"
#include "base/log.h"
//
// Miscellaneous helper macros.
@ -1846,4 +1846,4 @@ using Quatf = Quaternion<float>;
} // namespace base
#endif // VEC_MATH_H
#endif // BASE_VEC_MATH_H

View File

@ -1,12 +1,12 @@
#include "credits.h"
#include "demo/credits.h"
#include "../base/log.h"
#include "../base/vecmath.h"
#include "../engine/engine.h"
#include "../engine/font.h"
#include "../engine/image.h"
#include "../engine/input_event.h"
#include "demo.h"
#include "base/log.h"
#include "base/vecmath.h"
#include "demo/demo.h"
#include "engine/engine.h"
#include "engine/font.h"
#include "engine/image.h"
#include "engine/input_event.h"
using namespace base;
using namespace eng;

View File

@ -1,11 +1,11 @@
#ifndef CREDITS_H
#define CREDITS_H
#ifndef DEMO_CREDITS_H
#define DEMO_CREDITS_H
#include <memory>
#include <string>
#include "../engine/animator.h"
#include "../engine/image_quad.h"
#include "engine/animator.h"
#include "engine/image_quad.h"
namespace eng {
class Image;
@ -35,4 +35,4 @@ class Credits {
std::unique_ptr<eng::Image> CreateImage();
};
#endif // CREDITS_H
#endif // DEMO_CREDITS_H

View File

@ -1,5 +1,5 @@
#ifndef DAMAGE_TYPE_H
#define DAMAGE_TYPE_H
#ifndef DEMO_DAMAGE_TYPE_H
#define DEMO_DAMAGE_TYPE_H
enum DamageType {
kDamageType_Invalid = -1,
@ -30,4 +30,4 @@ enum SpeedType {
kSpeedType_Max
};
#endif // DAMAGE_TYPE_H
#endif // DEMO_DAMAGE_TYPE_H

View File

@ -1,19 +1,19 @@
#include "demo.h"
#include "demo/demo.h"
#include <algorithm>
#include <atomic>
#include <iostream>
#include <string>
#include "../base/file.h"
#include "../base/interpolation.h"
#include "../base/log.h"
#include "../base/random.h"
#include "../base/timer.h"
#include "../engine/engine.h"
#include "../engine/game_factory.h"
#include "../engine/input_event.h"
#include "../engine/sound.h"
#include "base/file.h"
#include "base/interpolation.h"
#include "base/log.h"
#include "base/random.h"
#include "base/timer.h"
#include "engine/engine.h"
#include "engine/game_factory.h"
#include "engine/input_event.h"
#include "engine/sound.h"
DECLARE_GAME_BEGIN
DECLARE_GAME(Demo)

View File

@ -1,19 +1,20 @@
#ifndef DEMO_H
#define DEMO_H
#ifndef DEMO_DEMO_H
#define DEMO_DEMO_H
#include "../base/closure.h"
#include "../engine/animator.h"
#include "../engine/font.h"
#include "../engine/game.h"
#include "../engine/persistent_data.h"
#include "../engine/solid_quad.h"
#include "../engine/sound_player.h"
#include "credits.h"
#include "enemy.h"
#include "hud.h"
#include "menu.h"
#include "player.h"
#include "sky_quad.h"
#include "base/closure.h"
#include "engine/animator.h"
#include "engine/font.h"
#include "engine/game.h"
#include "engine/persistent_data.h"
#include "engine/solid_quad.h"
#include "engine/sound_player.h"
#include "demo/credits.h"
#include "demo/enemy.h"
#include "demo/hud.h"
#include "demo/menu.h"
#include "demo/player.h"
#include "demo/sky_quad.h"
// #define LOAD_TEST
@ -127,4 +128,4 @@ class Demo : public eng::Game {
void BenchmarkResult(int avarage_fps);
};
#endif // DEMO_H
#endif // DEMO_DEMO_H

View File

@ -1,4 +1,4 @@
#include "enemy.h"
#include "demo/enemy.h"
#include <algorithm>
#include <functional>
@ -6,17 +6,18 @@
#include <tuple>
#include <vector>
#include "../base/collusion_test.h"
#include "../base/interpolation.h"
#include "../base/log.h"
#include "../engine/engine.h"
#include "../engine/font.h"
#include "../engine/image.h"
#include "../engine/renderer/geometry.h"
#include "../engine/renderer/shader.h"
#include "../engine/shader_source.h"
#include "../engine/sound.h"
#include "demo.h"
#include "base/collusion_test.h"
#include "base/interpolation.h"
#include "base/log.h"
#include "engine/engine.h"
#include "engine/font.h"
#include "engine/image.h"
#include "engine/renderer/geometry.h"
#include "engine/renderer/shader.h"
#include "engine/shader_source.h"
#include "engine/sound.h"
#include "demo/demo.h"
using namespace std::string_literals;

View File

@ -1,16 +1,17 @@
#ifndef ENEMY_H
#define ENEMY_H
#ifndef DEMO_ENEMY_H
#define DEMO_ENEMY_H
#include <array>
#include <list>
#include <memory>
#include "../base/vecmath.h"
#include "../engine/animator.h"
#include "../engine/image_quad.h"
#include "../engine/solid_quad.h"
#include "../engine/sound_player.h"
#include "damage_type.h"
#include "base/vecmath.h"
#include "engine/animator.h"
#include "engine/image_quad.h"
#include "engine/solid_quad.h"
#include "engine/sound_player.h"
#include "demo/damage_type.h"
namespace eng {
class Image;
@ -173,4 +174,4 @@ class Enemy {
void TranslateEnemyUnit(EnemyUnit& e, const base::Vector2f& delta);
};
#endif // ENEMY_H
#endif // DEMO_ENEMY_H

View File

@ -1,12 +1,13 @@
#include "hud.h"
#include "demo/hud.h"
#include "../base/interpolation.h"
#include "../base/log.h"
#include "../base/vecmath.h"
#include "../engine/engine.h"
#include "../engine/font.h"
#include "../engine/image.h"
#include "demo.h"
#include "base/interpolation.h"
#include "base/log.h"
#include "base/vecmath.h"
#include "engine/engine.h"
#include "engine/font.h"
#include "engine/image.h"
#include "demo/demo.h"
using namespace std::string_literals;

View File

@ -1,13 +1,13 @@
#ifndef HUD_H
#define HUD_H
#ifndef DEMO_HUD_H
#define DEMO_HUD_H
#include <memory>
#include <string>
#include "../base/closure.h"
#include "../engine/animator.h"
#include "../engine/image_quad.h"
#include "../engine/solid_quad.h"
#include "base/closure.h"
#include "engine/animator.h"
#include "engine/image_quad.h"
#include "engine/solid_quad.h"
namespace eng {
class Image;
@ -66,4 +66,4 @@ class Hud {
std::unique_ptr<eng::Image> CreateImage();
};
#endif // HUD_H
#endif // DEMO_HUD_H

View File

@ -1,18 +1,19 @@
#include "menu.h"
#include "demo/menu.h"
#include <cmath>
#include <string>
#include <vector>
#include "../base/collusion_test.h"
#include "../base/interpolation.h"
#include "../base/log.h"
#include "../engine/engine.h"
#include "../engine/font.h"
#include "../engine/image.h"
#include "../engine/input_event.h"
#include "../engine/sound.h"
#include "demo.h"
#include "base/collusion_test.h"
#include "base/interpolation.h"
#include "base/log.h"
#include "engine/engine.h"
#include "engine/font.h"
#include "engine/image.h"
#include "engine/input_event.h"
#include "engine/sound.h"
#include "demo/demo.h"
using namespace std::string_literals;

View File

@ -1,14 +1,14 @@
#ifndef MENU_H
#define MENU_H
#ifndef DEMO_MENU_H
#define DEMO_MENU_H
#include <memory>
#include <string>
#include "../base/closure.h"
#include "../base/vecmath.h"
#include "../engine/animator.h"
#include "../engine/image_quad.h"
#include "../engine/sound_player.h"
#include "base/closure.h"
#include "base/vecmath.h"
#include "engine/animator.h"
#include "engine/image_quad.h"
#include "engine/sound_player.h"
namespace eng {
class Image;
@ -149,4 +149,4 @@ class Menu {
bool IsAnimating();
};
#endif // MENU_H
#endif // DEMO_MENU_H

View File

@ -1,12 +1,13 @@
#include "player.h"
#include "demo/player.h"
#include "../base/interpolation.h"
#include "../base/log.h"
#include "../engine/engine.h"
#include "../engine/font.h"
#include "../engine/input_event.h"
#include "../engine/sound.h"
#include "demo.h"
#include "base/interpolation.h"
#include "base/log.h"
#include "engine/engine.h"
#include "engine/font.h"
#include "engine/input_event.h"
#include "engine/sound.h"
#include "demo/demo.h"
using namespace base;
using namespace eng;

View File

@ -1,14 +1,15 @@
#ifndef PLAYER_H
#define PLAYER_H
#ifndef DEMO_PLAYER_H
#define DEMO_PLAYER_H
#include <memory>
#include "../base/vecmath.h"
#include "../engine/animator.h"
#include "../engine/image_quad.h"
#include "../engine/solid_quad.h"
#include "../engine/sound_player.h"
#include "damage_type.h"
#include "base/vecmath.h"
#include "engine/animator.h"
#include "engine/image_quad.h"
#include "engine/solid_quad.h"
#include "engine/sound_player.h"
#include "demo/damage_type.h"
namespace eng {
class InputEvent;
@ -104,4 +105,4 @@ class Player {
bool CreateRenderResources();
};
#endif // PLAYER_H
#endif // DEMO_PLAYER_H

View File

@ -1,12 +1,12 @@
#include "sky_quad.h"
#include "demo/sky_quad.h"
#include "../base/interpolation.h"
#include "../base/log.h"
#include "../base/random.h"
#include "../engine/engine.h"
#include "../engine/renderer/geometry.h"
#include "../engine/renderer/shader.h"
#include "../engine/shader_source.h"
#include "base/interpolation.h"
#include "base/log.h"
#include "base/random.h"
#include "engine/engine.h"
#include "engine/renderer/geometry.h"
#include "engine/renderer/shader.h"
#include "engine/shader_source.h"
using namespace base;
using namespace eng;

View File

@ -1,9 +1,9 @@
#ifndef SKY_QUAD_H
#define SKY_QUAD_H
#ifndef DEMO_SKY_QUAD_H
#define DEMO_SKY_QUAD_H
#include "../base/vecmath.h"
#include "../engine/animatable.h"
#include "../engine/animator.h"
#include "base/vecmath.h"
#include "engine/animatable.h"
#include "engine/animator.h"
#include <array>
#include <memory>
@ -61,4 +61,4 @@ class SkyQuad : public eng::Animatable {
bool CreateShaders();
};
#endif // SKY_QUAD_H
#endif // DEMO_SKY_QUAD_H

View File

@ -1,4 +1,4 @@
#include "animatable.h"
#include "engine/animatable.h"
#include <cmath>

View File

@ -1,8 +1,8 @@
#ifndef SHAPE_H
#define SHAPE_H
#ifndef ENGINE_SHAPE_H
#define ENGINE_SHAPE_H
#include "../base/vecmath.h"
#include "drawable.h"
#include "base/vecmath.h"
#include "engine/drawable.h"
namespace eng {
@ -59,4 +59,4 @@ class Animatable : public Drawable {
} // namespace eng
#endif // SHAPE_H
#endif // ENGINE_SHAPE_H

View File

@ -1,9 +1,9 @@
#include "animator.h"
#include "../base/interpolation.h"
#include "../base/log.h"
#include "animatable.h"
#include "engine.h"
#include "base/interpolation.h"
#include "base/log.h"
#include "engine/animatable.h"
#include "engine/engine.h"
using namespace base;

View File

@ -1,10 +1,10 @@
#ifndef ANIMATOR_H
#define ANIMATOR_H
#ifndef ENGINE_ANIMATOR_H
#define ENGINE_ANIMATOR_H
#include <vector>
#include "../base/closure.h"
#include "../base/vecmath.h"
#include "base/closure.h"
#include "base/vecmath.h"
namespace eng {
@ -129,4 +129,4 @@ class Animator {
} // namespace eng
#endif // ANIMATOR_H
#endif // ENGINE_ANIMATOR_H

View File

@ -1,10 +1,10 @@
#ifndef AUDIO_H
#define AUDIO_H
#ifndef ENGINE_AUDIO_AUDIO_H
#define ENGINE_AUDIO_AUDIO_H
#if defined(__ANDROID__)
#include "audio_oboe.h"
#include "engine/audio/audio_oboe.h"
#elif defined(__linux__)
#include "audio_alsa.h"
#include "engine/audio/audio_alsa.h"
#endif
namespace eng {
@ -17,4 +17,4 @@ using Audio = AudioAlsa;
} // namespace eng
#endif // AUDIO_H
#endif // ENGINE_AUDIO_AUDIO_H

View File

@ -1,10 +1,10 @@
#include "audio_alsa.h"
#include <alsa/asoundlib.h>
#include "engine/audio/audio_alsa.h"
#include <memory>
#include "../../base/log.h"
#include <alsa/asoundlib.h>
#include "base/log.h"
using namespace base;

View File

@ -1,10 +1,10 @@
#ifndef AUDIO_ALSA_H
#define AUDIO_ALSA_H
#ifndef ENGINE_AUDIO_AUDIO_ALSA_H
#define ENGINE_AUDIO_AUDIO_ALSA_H
#include <atomic>
#include <thread>
#include "audio_base.h"
#include "engine/audio/audio_base.h"
typedef struct _snd_pcm snd_pcm_t;
@ -44,4 +44,4 @@ class AudioAlsa : public AudioBase {
} // namespace eng
#endif // AUDIO_ALSA_H
#endif // ENGINE_AUDIO_AUDIO_ALSA_H

View File

@ -1,11 +1,11 @@
#include "audio.h"
#include "engine/audio/audio.h"
#include <cstring>
#include "../../base/log.h"
#include "../../base/task_runner.h"
#include "../../base/worker.h"
#include "../sound.h"
#include "base/log.h"
#include "base/task_runner.h"
#include "base/thread_pool.h"
#include "engine/sound.h"
using namespace base;
@ -16,13 +16,13 @@ AudioBase::AudioBase()
AudioBase::~AudioBase() = default;
size_t AudioBase::CreateResource() {
size_t resource_id = ++last_resource_id_;
uint64_t AudioBase::CreateResource() {
uint64_t resource_id = ++last_resource_id_;
resources_[resource_id] = std::make_shared<Resource>();
return resource_id;
}
void AudioBase::DestroyResource(size_t resource_id) {
void AudioBase::DestroyResource(uint64_t resource_id) {
auto it = resources_.find(resource_id);
if (it == resources_.end())
return;
@ -31,7 +31,7 @@ void AudioBase::DestroyResource(size_t resource_id) {
resources_.erase(it);
}
void AudioBase::Play(size_t resource_id,
void AudioBase::Play(uint64_t resource_id,
std::shared_ptr<Sound> sound,
float amplitude,
bool reset_pos) {
@ -75,7 +75,7 @@ void AudioBase::Play(size_t resource_id,
play_list_[0].push_back(it->second);
}
void AudioBase::Stop(size_t resource_id) {
void AudioBase::Stop(uint64_t resource_id) {
auto it = resources_.find(resource_id);
if (it == resources_.end())
return;
@ -84,7 +84,7 @@ void AudioBase::Stop(size_t resource_id) {
it->second->flags.fetch_or(kStopped, std::memory_order_relaxed);
}
void AudioBase::SetLoop(size_t resource_id, bool loop) {
void AudioBase::SetLoop(uint64_t resource_id, bool loop) {
auto it = resources_.find(resource_id);
if (it == resources_.end())
return;
@ -95,7 +95,7 @@ void AudioBase::SetLoop(size_t resource_id, bool loop) {
it->second->flags.fetch_and(~kLoop, std::memory_order_relaxed);
}
void AudioBase::SetSimulateStereo(size_t resource_id, bool simulate) {
void AudioBase::SetSimulateStereo(uint64_t resource_id, bool simulate) {
auto it = resources_.find(resource_id);
if (it == resources_.end())
return;
@ -106,7 +106,7 @@ void AudioBase::SetSimulateStereo(size_t resource_id, bool simulate) {
it->second->flags.fetch_and(~kSimulateStereo, std::memory_order_relaxed);
}
void AudioBase::SetResampleStep(size_t resource_id, size_t step) {
void AudioBase::SetResampleStep(uint64_t resource_id, size_t step) {
auto it = resources_.find(resource_id);
if (it == resources_.end())
return;
@ -114,7 +114,7 @@ void AudioBase::SetResampleStep(size_t resource_id, size_t step) {
it->second->step.store(step + 100, std::memory_order_relaxed);
}
void AudioBase::SetMaxAmplitude(size_t resource_id, float max_amplitude) {
void AudioBase::SetMaxAmplitude(uint64_t resource_id, float max_amplitude) {
auto it = resources_.find(resource_id);
if (it == resources_.end())
return;
@ -122,7 +122,7 @@ void AudioBase::SetMaxAmplitude(size_t resource_id, float max_amplitude) {
it->second->max_amplitude.store(max_amplitude, std::memory_order_relaxed);
}
void AudioBase::SetAmplitudeInc(size_t resource_id, float amplitude_inc) {
void AudioBase::SetAmplitudeInc(uint64_t resource_id, float amplitude_inc) {
auto it = resources_.find(resource_id);
if (it == resources_.end())
return;
@ -130,7 +130,7 @@ void AudioBase::SetAmplitudeInc(size_t resource_id, float amplitude_inc) {
it->second->amplitude_inc.store(amplitude_inc, std::memory_order_relaxed);
}
void AudioBase::SetEndCallback(size_t resource_id, base::Closure cb) {
void AudioBase::SetEndCallback(uint64_t resource_id, base::Closure cb) {
auto it = resources_.find(resource_id);
if (it == resources_.end())
return;
@ -236,8 +236,9 @@ void AudioBase::RenderAudio(float* output_buffer, size_t num_frames) {
src[1] = src[0]; // mono.
num_samples = sound->GetNumSamples();
Worker::Get().PostTask(HERE, std::bind(&AudioBase::DoStream, this,
*it, flags & kLoop));
ThreadPool::Get().PostTask(
HERE,
std::bind(&AudioBase::DoStream, this, *it, flags & kLoop));
} else if (num_samples) {
DLOG << "Buffer underrun!";
src_index %= num_samples;

View File

@ -1,12 +1,12 @@
#ifndef AUDIO_BASE_H
#define AUDIO_BASE_H
#ifndef ENGINE_AUDIO_AUDIO_BASE_H
#define ENGINE_AUDIO_AUDIO_BASE_H
#include <list>
#include <memory>
#include <mutex>
#include <unordered_map>
#include "../../base/closure.h"
#include "base/closure.h"
namespace base {
class TaskRunner;
@ -21,21 +21,21 @@ class Sound;
// thread.
class AudioBase {
public:
size_t CreateResource();
void DestroyResource(size_t resource_id);
uint64_t CreateResource();
void DestroyResource(uint64_t resource_id);
void Play(size_t resource_id,
void Play(uint64_t resource_id,
std::shared_ptr<Sound> sound,
float amplitude,
bool reset_pos);
void Stop(size_t resource_id);
void Stop(uint64_t resource_id);
void SetLoop(size_t resource_id, bool loop);
void SetSimulateStereo(size_t resource_id, bool simulate);
void SetResampleStep(size_t resource_id, size_t step);
void SetMaxAmplitude(size_t resource_id, float max_amplitude);
void SetAmplitudeInc(size_t resource_id, float amplitude_inc);
void SetEndCallback(size_t resource_id, base::Closure cb);
void SetLoop(uint64_t resource_id, bool loop);
void SetSimulateStereo(uint64_t resource_id, bool simulate);
void SetResampleStep(uint64_t resource_id, size_t step);
void SetMaxAmplitude(uint64_t resource_id, float max_amplitude);
void SetAmplitudeInc(uint64_t resource_id, float amplitude_inc);
void SetEndCallback(uint64_t resource_id, base::Closure cb);
void SetEnableAudio(bool enable) { audio_enabled_ = enable; }
@ -71,8 +71,8 @@ class AudioBase {
std::atomic<bool> streaming_in_progress{false};
};
std::unordered_map<size_t, std::shared_ptr<Resource>> resources_;
size_t last_resource_id_ = 0;
std::unordered_map<uint64_t, std::shared_ptr<Resource>> resources_;
uint64_t last_resource_id_ = 0;
std::list<std::shared_ptr<Resource>> play_list_[2];
std::mutex lock_;
@ -93,4 +93,4 @@ class AudioBase {
} // namespace eng
#endif // AUDIO_BASE_H
#endif // ENGINE_AUDIO_AUDIO_BASE_H

View File

@ -1,5 +1,5 @@
#ifndef AUDIO_FORWARD_H
#define AUDIO_FORWARD_H
#ifndef ENGINE_AUDIO_AUDIO_FORWARD_H
#define ENGINE_AUDIO_AUDIO_FORWARD_H
namespace eng {
@ -13,4 +13,4 @@ using Audio = AudioAlsa;
} // namespace eng
#endif // AUDIO_FORWARD_H
#endif // ENGINE_AUDIO_AUDIO_FORWARD_H

View File

@ -1,7 +1,7 @@
#include "audio_oboe.h"
#include "engine/audio/audio_oboe.h"
#include "../../base/log.h"
#include "../../third_party/oboe/include/oboe/Oboe.h"
#include "base/log.h"
#include "third_party/oboe/include/oboe/Oboe.h"
using namespace base;

View File

@ -1,11 +1,12 @@
#ifndef AUDIO_OBOE_H
#define AUDIO_OBOE_H
#ifndef ENGINE_AUDIO_AUDIO_OBOE_H
#define ENGINE_AUDIO_AUDIO_OBOE_H
#include <memory>
#include "../../third_party/oboe/include/oboe/AudioStream.h"
#include "../../third_party/oboe/include/oboe/AudioStreamCallback.h"
#include "audio_base.h"
#include "third_party/oboe/include/oboe/AudioStream.h"
#include "third_party/oboe/include/oboe/AudioStreamCallback.h"
#include "engine/audio/audio_base.h"
namespace eng {
@ -48,4 +49,4 @@ class AudioOboe : public AudioBase {
} // namespace eng
#endif // AUDIO_OBOE_H
#endif // ENGINE_AUDIO_AUDIO_OBOE_H

View File

@ -1,5 +1,6 @@
#include "drawable.h"
#include "engine.h"
#include "engine/drawable.h"
#include "engine/engine.h"
namespace eng {

View File

@ -1,7 +1,7 @@
#ifndef DRAWABLE_H
#define DRAWABLE_H
#ifndef ENGINE_DRAWABLE_H
#define ENGINE_DRAWABLE_H
#include "../base/vecmath.h"
#include "base/vecmath.h"
namespace eng {
@ -28,4 +28,4 @@ class Drawable {
} // namespace eng
#endif // DRAWABLE_H
#endif // ENGINE_DRAWABLE_H

View File

@ -1,23 +1,23 @@
#include "engine.h"
#include "engine/engine.h"
#include "../base/log.h"
#include "../third_party/texture_compressor/texture_compressor.h"
#include "animator.h"
#include "audio/audio.h"
#include "drawable.h"
#include "font.h"
#include "game.h"
#include "game_factory.h"
#include "image.h"
#include "image_quad.h"
#include "input_event.h"
#include "mesh.h"
#include "platform/platform.h"
#include "renderer/geometry.h"
#include "renderer/renderer.h"
#include "renderer/shader.h"
#include "renderer/texture.h"
#include "shader_source.h"
#include "base/log.h"
#include "engine/animator.h"
#include "engine/audio/audio.h"
#include "engine/drawable.h"
#include "engine/font.h"
#include "engine/game.h"
#include "engine/game_factory.h"
#include "engine/image.h"
#include "engine/image_quad.h"
#include "engine/input_event.h"
#include "engine/mesh.h"
#include "engine/platform/platform.h"
#include "engine/renderer/geometry.h"
#include "engine/renderer/renderer.h"
#include "engine/renderer/shader.h"
#include "engine/renderer/texture.h"
#include "engine/shader_source.h"
#include "third_party/texture_compressor/texture_compressor.h"
using namespace base;

View File

@ -1,5 +1,5 @@
#ifndef ENGINE_H
#define ENGINE_H
#ifndef ENGINE_ENGINE_H
#define ENGINE_ENGINE_H
#include <deque>
#include <functional>
@ -7,10 +7,10 @@
#include <memory>
#include <unordered_map>
#include "../base/random.h"
#include "../base/vecmath.h"
#include "audio/audio_forward.h"
#include "persistent_data.h"
#include "base/random.h"
#include "base/vecmath.h"
#include "engine/audio/audio_forward.h"
#include "engine/persistent_data.h"
class TextureCompressor;
@ -221,4 +221,4 @@ class Engine {
} // namespace eng
#endif // ENGINE_H
#endif // ENGINE_ENGINE_H

View File

@ -1,11 +1,11 @@
#include "font.h"
#include "engine/font.h"
#include <codecvt>
#include <locale>
#include "../base/log.h"
#include "engine.h"
#include "platform/asset_file.h"
#include "base/log.h"
#include "engine/engine.h"
#include "engine/platform/asset_file.h"
#define STB_TRUETYPE_IMPLEMENTATION
#include "../third_party/stb/stb_truetype.h"

View File

@ -1,11 +1,11 @@
#ifndef FONT_H
#define FONT_H
#ifndef ENGINE_FONT_H
#define ENGINE_FONT_H
#include <cstdint>
#include <memory>
#include <string>
#include "../third_party/stb/stb_truetype.h"
#include "third_party/stb/stb_truetype.h"
namespace eng {
@ -51,4 +51,4 @@ class Font {
} // namespace eng
#endif // FONT_H
#endif // ENGINE_FONT_H

View File

@ -1,5 +1,5 @@
#ifndef GAME_H
#define GAME_H
#ifndef ENGINE_GAME_H
#define ENGINE_GAME_H
namespace eng {
@ -25,4 +25,4 @@ class Game {
} // namespace eng
#endif // GAME_H
#endif // ENGINE_GAME_H

View File

@ -1,5 +1,5 @@
#ifndef GAME_FACTORY_H
#define GAME_FACTORY_H
#ifndef ENGINE_GAME_FACTORY_H
#define ENGINE_GAME_FACTORY_H
#include <memory>
#include <string>
@ -52,4 +52,4 @@ class GameFactory : public GameFactoryBase {
} // namespace eng
#endif // GAME_FACTORY_H
#endif // ENGINE_GAME_FACTORY_H

View File

@ -1,14 +1,14 @@
#include "image.h"
#include "engine/image.h"
#include <algorithm>
#include <cmath>
#include "../base/interpolation.h"
#include "../base/log.h"
#include "../base/misc.h"
#include "../third_party/texture_compressor/texture_compressor.h"
#include "engine.h"
#include "platform/asset_file.h"
#include "base/interpolation.h"
#include "base/log.h"
#include "base/misc.h"
#include "third_party/texture_compressor/texture_compressor.h"
#include "engine/engine.h"
#include "engine/platform/asset_file.h"
// This 3rd party library is written in C and uses malloc, which means that we
// have to do the same.

View File

@ -1,11 +1,11 @@
#ifndef IMAGE_H
#define IMAGE_H
#ifndef ENGINE_IMAGE_H
#define ENGINE_IMAGE_H
#include <stdint.h>
#include <string>
#include "../base/mem.h"
#include "../base/vecmath.h"
#include "base/mem.h"
#include "base/vecmath.h"
namespace eng {
@ -56,4 +56,4 @@ class Image {
} // namespace eng
#endif // IMAGE_H
#endif // ENGINE_IMAGE_H

View File

@ -1,10 +1,10 @@
#include "image_quad.h"
#include "engine/image_quad.h"
#include "../base/log.h"
#include "engine.h"
#include "renderer/geometry.h"
#include "renderer/shader.h"
#include "renderer/texture.h"
#include "base/log.h"
#include "engine/engine.h"
#include "engine/renderer/geometry.h"
#include "engine/renderer/shader.h"
#include "engine/renderer/texture.h"
using namespace base;

View File

@ -1,8 +1,5 @@
#ifndef IMAGE_QUAD_H
#define IMAGE_QUAD_H
#include "../base/vecmath.h"
#include "animatable.h"
#ifndef ENGINE_IMAGE_QUAD_H
#define ENGINE_IMAGE_QUAD_H
#include <array>
#include <memory>
@ -10,6 +7,9 @@
#include <unordered_map>
#include <variant>
#include "base/vecmath.h"
#include "engine/animatable.h"
namespace eng {
class Shader;
@ -76,4 +76,4 @@ class ImageQuad : public Animatable {
} // namespace eng
#endif // IMAGE_QUAD_H
#endif // ENGINE_IMAGE_QUAD_H

View File

@ -1,8 +1,8 @@
#ifndef INPUT_EVENT_H
#define INPUT_EVENT_H
#ifndef ENGINE_INPUT_EVENT_H
#define ENGINE_INPUT_EVENT_H
#include "../base/log.h"
#include "../base/vecmath.h"
#include "base/log.h"
#include "base/vecmath.h"
namespace eng {
@ -44,4 +44,4 @@ class InputEvent {
} // namespace eng
#endif // INPUT_EVENT_H
#endif // ENGINE_INPUT_EVENT_H

View File

@ -1,11 +1,11 @@
#include "mesh.h"
#include "engine/mesh.h"
#include <string.h>
#include "../base/log.h"
#include "../third_party/jsoncpp/json.h"
#include "engine.h"
#include "platform/asset_file.h"
#include "base/log.h"
#include "third_party/jsoncpp/json.h"
#include "engine/engine.h"
#include "engine/platform/asset_file.h"
namespace eng {

View File

@ -1,9 +1,10 @@
#ifndef MESH_H
#define MESH_H
#ifndef ENGINE_MESH_H
#define ENGINE_MESH_H
#include <memory>
#include <string>
#include "renderer/renderer_types.h"
#include "engine/renderer/renderer_types.h"
namespace eng {
@ -50,4 +51,4 @@ class Mesh {
} // namespace eng
#endif // MESH_H
#endif // ENGINE_MESH_H

View File

@ -1,10 +1,10 @@
#include "persistent_data.h"
#include "engine/persistent_data.h"
#include <memory>
#include "../base/file.h"
#include "engine.h"
#include "platform/asset_file.h"
#include "base/file.h"
#include "engine/engine.h"
#include "engine/platform/asset_file.h"
using namespace base;

View File

@ -1,10 +1,10 @@
#ifndef SAVE_GAME_H
#define SAVE_GAME_H
#ifndef ENGINE_SAVE_GAME_H
#define ENGINE_SAVE_GAME_H
#include <string>
#include "../base/log.h"
#include "../third_party/jsoncpp/json.h"
#include "base/log.h"
#include "third_party/jsoncpp/json.h"
namespace eng {
@ -37,4 +37,4 @@ class PersistentData {
} // namespace eng
#endif // SAVE_GAME_H
#endif // ENGINE_SAVE_GAME_H

View File

@ -1,5 +1,6 @@
#include "asset_file.h"
#include "../../base/log.h"
#include "engine/platform/asset_file.h"
#include "base/log.h"
namespace eng {

View File

@ -1,14 +1,15 @@
#ifndef ASSET_FILE_H
#define ASSET_FILE_H
#ifndef ENGINE_PLATFORM_ASSET_FILE_H
#define ENGINE_PLATFORM_ASSET_FILE_H
#include <memory>
#include <string>
#if defined(__ANDROID__)
#include <zlib.h>
#include "../../third_party/minizip/unzip.h"
#include "third_party/minizip/unzip.h"
#elif defined(__linux__)
#include "../../base/file.h"
#include "base/file.h"
#endif
#include <memory>
#include <string>
namespace eng {
@ -40,4 +41,4 @@ class AssetFile {
} // namespace eng
#endif // ASSET_FILE_H
#endif // ENGINE_PLATFORM_ASSET_FILE_H

View File

@ -1,6 +1,6 @@
#include <string>
#include "../../base/log.h"
#include "asset_file.h"
#include "engine/platform/asset_file.h"
#include "base/log.h"
namespace eng {

View File

@ -1,5 +1,4 @@
#include <string>
#include "asset_file.h"
#include "engine/platform/asset_file.h"
namespace eng {

View File

@ -1,11 +1,11 @@
#include "platform.h"
#include "engine/platform/platform.h"
#include "../../base/log.h"
#include "../../base/task_runner.h"
#include "../audio/audio.h"
#include "../engine.h"
#include "../renderer/opengl/renderer_opengl.h"
#include "../renderer/vulkan/renderer_vulkan.h"
#include "base/log.h"
#include "base/task_runner.h"
#include "engine/audio/audio.h"
#include "engine/engine.h"
#include "engine/renderer/opengl/renderer_opengl.h"
#include "engine/renderer/vulkan/renderer_vulkan.h"
#define VULKAN_RENDERER
@ -22,7 +22,7 @@ Platform::~Platform() = default;
void Platform::InitializeCommon() {
LOG << "Initializing platform.";
worker_.Initialize();
thread_pool_.Initialize();
TaskRunner::CreateThreadLocalTaskRunner();
audio_ = std::make_unique<Audio>();
@ -74,7 +74,7 @@ void Platform::RunMainLoop() {
engine_->Update(time_step);
if (should_exit_) {
worker_.Shutdown();
thread_pool_.Shutdown();
engine_->Shutdown();
engine_.reset();
return;

View File

@ -1,13 +1,13 @@
#ifndef PLATFORM_H
#define PLATFORM_H
#ifndef ENGINE_PLATFORM_PLATFORM_H
#define ENGINE_PLATFORM_PLATFORM_H
#include <exception>
#include <memory>
#include <string>
#include "../../base/timer.h"
#include "../../base/worker.h"
#include "../audio/audio_forward.h"
#include "base/thread_pool.h"
#include "base/timer.h"
#include "engine/audio/audio_forward.h"
#if defined(__ANDROID__)
@ -84,7 +84,7 @@ class Platform {
std::unique_ptr<Renderer> renderer_;
std::unique_ptr<Engine> engine_;
base::Worker worker_;
base::ThreadPool thread_pool_;
#if defined(__ANDROID__)
@ -115,4 +115,4 @@ class Platform {
} // namespace eng
#endif // PLATFORM_H
#endif // ENGINE_PLATFORM_PLATFORM_H

View File

@ -1,18 +1,15 @@
#include "platform.h"
#include "engine/platform/platform.h"
#include <android_native_app_glue.h>
#include <jni.h>
#include <unistd.h>
#include <memory>
#include <string>
#include "../../base/log.h"
#include "../../base/task_runner.h"
#include "../audio/audio.h"
#include "../engine.h"
#include "../input_event.h"
#include "../renderer/renderer.h"
#include "base/log.h"
#include "base/task_runner.h"
#include "engine/audio/audio.h"
#include "engine/engine.h"
#include "engine/input_event.h"
#include "engine/renderer/renderer.h"
using namespace base;

View File

@ -1,14 +1,12 @@
#include "platform.h"
#include "engine/platform/platform.h"
#include <memory>
#include "../../base/log.h"
#include "../../base/task_runner.h"
#include "../../base/vecmath.h"
#include "../audio/audio.h"
#include "../engine.h"
#include "../input_event.h"
#include "../renderer/renderer.h"
#include "base/log.h"
#include "base/task_runner.h"
#include "base/vecmath.h"
#include "engine/audio/audio.h"
#include "engine/engine.h"
#include "engine/input_event.h"
#include "engine/renderer/renderer.h"
using namespace base;

View File

@ -1,7 +1,7 @@
#include "geometry.h"
#include "engine/renderer/geometry.h"
#include "../mesh.h"
#include "renderer.h"
#include "engine/mesh.h"
#include "engine/renderer/renderer.h"
namespace eng {

View File

@ -1,11 +1,11 @@
#ifndef GEOMETRY_H
#define GEOMETRY_H
#ifndef ENGINE_RENDERER_GEOMETRY_H
#define ENGINE_RENDERER_GEOMETRY_H
#include <memory>
#include <string>
#include "render_resource.h"
#include "renderer_types.h"
#include "engine/renderer/render_resource.h"
#include "engine/renderer/renderer_types.h"
namespace eng {
@ -36,4 +36,4 @@ class Geometry : public RenderResource {
} // namespace eng
#endif // GEOMETRY_H
#endif // ENGINE_RENDERER_GEOMETRY_H

View File

@ -1,16 +1,16 @@
#ifndef OPENGL_H
#define OPENGL_H
#ifndef ENGINE_RENDERER_OPENGL_OPENGL_H
#define ENGINE_RENDERER_OPENGL_OPENGL_H
#if defined(__ANDROID__)
// Use the modified Khronos header from ndk-helper. This gives access to
// additional functionality the drivers may expose but which the system headers
// do not.
#include "../../../third_party/android/gl3stub.h"
#include "third_party/android/gl3stub.h"
#include <GLES2/gl2ext.h>
#elif defined(__linux__)
#include "../../../third_party/glew/glew.h"
#include "../../../third_party/glew/glxew.h"
#include "third_party/glew/glew.h"
#include "third_party/glew/glxew.h"
// Define the missing format for the etc1
#ifndef GL_ETC1_RGB8_OES
@ -19,4 +19,4 @@
#endif
#endif // OPENGL_H
#endif // ENGINE_RENDERER_OPENGL_OPENGL_H

View File

@ -1,8 +1,8 @@
#include "render_command.h"
#include "engine/renderer/opengl/render_command.h"
#include "../../image.h"
#include "../../mesh.h"
#include "../../shader_source.h"
#include "engine/image.h"
#include "engine/mesh.h"
#include "engine/shader_source.h"
#ifdef _DEBUG
#define RENDER_COMMAND_IMPL(NAME, GLOBAL) \

View File

@ -1,13 +1,13 @@
#ifndef RENDER_COMMAND_H
#define RENDER_COMMAND_H
#ifndef ENGINE_RENDERER_OPENGL_RENDER_COMMAND_H
#define ENGINE_RENDERER_OPENGL_RENDER_COMMAND_H
#include <array>
#include <memory>
#include <string>
#include "../../../base/hash.h"
#include "../../../base/vecmath.h"
#include "../renderer_types.h"
#include "base/hash.h"
#include "base/vecmath.h"
#include "engine/renderer/renderer_types.h"
namespace eng {
@ -17,7 +17,7 @@ class Mesh;
#define RENDER_COMMAND_BEGIN(NAME) \
struct NAME : RenderCommand { \
static constexpr CommandId CMD_ID = HHASH(#NAME); \
static constexpr CommandId CMD_ID = base::Hash(#NAME); \
NAME();
#define RENDER_COMMAND_END \
} \
@ -136,4 +136,4 @@ RENDER_COMMAND_END
} // namespace eng
#endif // RENDER_COMMAND_H
#endif // ENGINE_RENDERER_OPENGL_RENDER_COMMAND_H

View File

@ -1,22 +1,25 @@
#include "renderer_opengl.h"
// © 2021 Attila Uygun <auygun@gmail.com>
// Licensed under the MIT license.
#include "engine/renderer/opengl/renderer_opengl.h"
#include <algorithm>
#include <cstring>
#include <sstream>
#include <unordered_set>
#include "../../../base/log.h"
#include "../../../base/vecmath.h"
#include "base/log.h"
#include "base/vecmath.h"
#ifdef THREADED_RENDERING
#include "../../../base/task_runner.h"
#include "base/task_runner.h"
#endif // THREADED_RENDERING
#include "../../image.h"
#include "../../mesh.h"
#include "../../shader_source.h"
#include "../geometry.h"
#include "../shader.h"
#include "../texture.h"
#include "render_command.h"
#include "engine/image.h"
#include "engine/mesh.h"
#include "engine/renderer/geometry.h"
#include "engine/renderer/opengl/render_command.h"
#include "engine/renderer/shader.h"
#include "engine/renderer/texture.h"
#include "engine/shader_source.h"
using namespace base;

View File

@ -1,5 +1,5 @@
#ifndef RENDERER_OPENGL_H
#define RENDERER_OPENGL_H
#ifndef ENGINE_RENDERER_OPENGL_RENDERER_OPENGL_H
#define ENGINE_RENDERER_OPENGL_RENDERER_OPENGL_H
#include <memory>
#include <string>
@ -15,12 +15,12 @@
#include <mutex>
#include <thread>
#include "../../../base/semaphore.h"
#include "base/semaphore.h"
#endif // THREADED_RENDERING
#include "opengl.h"
#include "engine/renderer/opengl/opengl.h"
#include "../renderer.h"
#include "engine/renderer/renderer.h"
#if defined(__ANDROID__)
struct ANativeWindow;
@ -213,4 +213,4 @@ class RendererOpenGL : public Renderer {
} // namespace eng
#endif // RENDERER_OPENGL_H
#endif // ENGINE_RENDERER_OPENGL_RENDERER_OPENGL_H

View File

@ -1,9 +1,9 @@
#include "renderer_opengl.h"
#include "engine/renderer/opengl/renderer_opengl.h"
#include <android/native_window.h>
#include "../../../base/log.h"
#include "../../../third_party/android/GLContext.h"
#include "base/log.h"
#include "third_party/android/GLContext.h"
namespace eng {

View File

@ -1,6 +1,6 @@
#include "renderer_opengl.h"
#include "engine/renderer/opengl/renderer_opengl.h"
#include "../../../base/log.h"
#include "base/log.h"
namespace eng {

View File

@ -1,5 +1,5 @@
#ifndef RENDER_RESOURCE_H
#define RENDER_RESOURCE_H
#ifndef ENGINE_RENDERER_RENDER_RESOURCE_H
#define ENGINE_RENDERER_RENDER_RESOURCE_H
#include <cstdint>
@ -27,4 +27,4 @@ class RenderResource {
} // namespace eng
#endif // RENDER_RESOURCE_H
#endif // ENGINE_RENDERER_RENDER_RESOURCE_H

View File

@ -1,5 +1,5 @@
#ifndef RENDERER_H
#define RENDERER_H
#ifndef ENGINE_RENDERER_RENDERER_H
#define ENGINE_RENDERER_RENDERER_H
#include <memory>
#include <string>
@ -9,9 +9,9 @@
#include <X11/Xutil.h>
#endif
#include "../../base/closure.h"
#include "../../base/vecmath.h"
#include "renderer_types.h"
#include "base/closure.h"
#include "base/vecmath.h"
#include "engine/renderer/renderer_types.h"
#if defined(__ANDROID__)
struct ANativeWindow;
@ -127,4 +127,4 @@ class Renderer {
} // namespace eng
#endif // RENDERER_H
#endif // ENGINE_RENDERER_RENDERER_H

View File

@ -1,8 +1,8 @@
#include "renderer_types.h"
#include "engine/renderer/renderer_types.h"
#include <cstring>
#include "../../base/log.h"
#include "base/log.h"
namespace {

View File

@ -1,5 +1,5 @@
#ifndef RENDERER_TYPES_H
#define RENDERER_TYPES_H
#ifndef ENGINE_RENDERER_RENDERER_TYPES_H
#define ENGINE_RENDERER_RENDERER_TYPES_H
#include <string>
#include <tuple>
@ -45,4 +45,4 @@ bool ParseVertexDescription(std::string vd_str, VertexDescripton& out);
} // namespace eng
#endif // RENDERER_TYPES_H
#endif // ENGINE_RENDERER_RENDERER_TYPES_H

View File

@ -1,7 +1,7 @@
#include "shader.h"
#include "engine/renderer/shader.h"
#include "../shader_source.h"
#include "renderer.h"
#include "engine/renderer/renderer.h"
#include "engine/shader_source.h"
using namespace base;

View File

@ -1,12 +1,12 @@
#ifndef SHADER_H
#define SHADER_H
#ifndef ENGINE_RENDERER_SHADER_H
#define ENGINE_RENDERER_SHADER_H
#include <memory>
#include <string>
#include "../../base/vecmath.h"
#include "render_resource.h"
#include "renderer_types.h"
#include "base/vecmath.h"
#include "engine/renderer/render_resource.h"
#include "engine/renderer/renderer_types.h"
namespace eng {
@ -39,4 +39,4 @@ class Shader : public RenderResource {
} // namespace eng
#endif // SHADER_H
#endif // ENGINE_RENDERER_SHADER_H

View File

@ -1,8 +1,8 @@
#include "texture.h"
#include "engine/renderer/texture.h"
#include "../../base/log.h"
#include "../image.h"
#include "renderer.h"
#include "base/log.h"
#include "engine//image.h"
#include "engine/renderer/renderer.h"
namespace eng {

View File

@ -1,10 +1,10 @@
#ifndef TEXTURE_H
#define TEXTURE_H
#ifndef ENGINE_RENDERER_TEXTURE_H
#define ENGINE_RENDERER_TEXTURE_H
#include <memory>
#include <string>
#include "render_resource.h"
#include "engine/renderer/render_resource.h"
namespace eng {
@ -32,4 +32,4 @@ class Texture : public RenderResource {
} // namespace eng
#endif // TEXTURE_H
#endif // ENGINE_RENDERER_TEXTURE_H

View File

@ -1,22 +1,22 @@
#include "renderer_vulkan.h"
#include "engine/renderer/vulkan/renderer_vulkan.h"
#include <algorithm>
#include <cstring>
#include <sstream>
#include "../../../base/log.h"
#include "../../../base/vecmath.h"
#include "../../../third_party/glslang/SPIRV/GlslangToSpv.h"
#include "../../../third_party/glslang/StandAlone/ResourceLimits.h"
#include "../../../third_party/glslang/glslang/Include/Types.h"
#include "../../../third_party/glslang/glslang/Public/ShaderLang.h"
#include "../../../third_party/spirv-reflect/spirv_reflect.h"
#include "../../image.h"
#include "../../mesh.h"
#include "../../shader_source.h"
#include "../geometry.h"
#include "../shader.h"
#include "../texture.h"
#include "base/log.h"
#include "base/vecmath.h"
#include "engine/image.h"
#include "engine/mesh.h"
#include "engine/renderer/geometry.h"
#include "engine/renderer/shader.h"
#include "engine/renderer/texture.h"
#include "engine/shader_source.h"
#include "third_party/glslang/SPIRV/GlslangToSpv.h"
#include "third_party/glslang/StandAlone/ResourceLimits.h"
#include "third_party/glslang/glslang/Include/Types.h"
#include "third_party/glslang/glslang/Public/ShaderLang.h"
#include "third_party/spirv-reflect/spirv_reflect.h"
using namespace base;

View File

@ -1,5 +1,5 @@
#ifndef RENDERER_VULKAN_H
#define RENDERER_VULKAN_H
#ifndef ENGINE_RENDERER_VULKAN_RENDERER_VULKAN_H
#define ENGINE_RENDERER_VULKAN_RENDERER_VULKAN_H
#include <atomic>
#include <memory>
@ -8,12 +8,12 @@
#include <unordered_map>
#include <vector>
#include "vulkan_context.h"
#include "engine/renderer/vulkan/vulkan_context.h"
#include "../../../base/semaphore.h"
#include "../../../base/task_runner.h"
#include "../../../third_party/vma/vk_mem_alloc.h"
#include "../renderer.h"
#include "base/semaphore.h"
#include "base/task_runner.h"
#include "engine/renderer/renderer.h"
#include "third_party/vma/vk_mem_alloc.h"
namespace eng {
@ -268,4 +268,4 @@ class RendererVulkan : public Renderer {
} // namespace eng
#endif // RENDERER_VULKAN_H
#endif // ENGINE_RENDERER_VULKAN_RENDERER_VULKAN_H

Some files were not shown because too many files have changed in this diff Show More