Skip to content

Commit

Permalink
global code restyle (snake -> camel)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtiapko committed Jan 16, 2019
1 parent 233b8df commit 311351f
Show file tree
Hide file tree
Showing 114 changed files with 2,006 additions and 2,004 deletions.
8 changes: 4 additions & 4 deletions include/application.h → include/Application.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#ifndef __DK_APPLICATION_H__
#define __DK_APPLICATION_H__

#include "status.h"
#include "Status.h"

namespace dk
{

class application
class Application
{
public:
virtual ~application() noexcept = default;
virtual ~Application() noexcept = default;

virtual void update(float dt) noexcept = 0;
virtual void render() noexcept = 0;

virtual status create() noexcept = 0;
virtual Status create() noexcept = 0;
virtual void destroy() noexcept = 0;
};

Expand Down
2 changes: 1 addition & 1 deletion include/assert.h → include/Assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __DK_ASSERT_H__

#include <stdlib.h>
#include "log.h"
#include "Log.h"

#define DK_ASSERT(expr, ...) \
if (!(expr)) { \
Expand Down
12 changes: 6 additions & 6 deletions include/core.h → include/Core.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#ifndef __DK_CORE_H__
#define __DK_CORE_H__

#include "application.h"
#include "graph/renderer.h"
#include "Application.h"
#include "graph/Renderer.h"

namespace dk
{

class core
class Core
{
private:
static bool s_running;
static graph::renderer s_active_renderer;
static graph::Renderer s_active_renderer;

public:
template<typename T> static T* active() noexcept;

static status run(application* app) noexcept;
static Status run(Application* app) noexcept;
static void stop() noexcept;

// TODO: enum create all, only audio, only net, ... (multi using overloaded AND '&&')
static status create() noexcept;
static Status create() noexcept;
static void destroy() noexcept;
};

Expand Down
34 changes: 17 additions & 17 deletions include/log.h → include/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
#include <chrono>
#include <iomanip>
#include <iostream>
#include "status.h"
#include "util/term.h"
#include "Status.h"
#include "util/Term.h"

#define DK_LOG_PRINT(...) dk::log::print(__VA_ARGS__, '\n')
#define DK_LOG_PRINT(...) dk::Log::print(__VA_ARGS__, '\n')

#define DK_LOG_COLOR(color, ...) \
dk::util::term_text_color::color, dk::util::term_text_attrib::BOLD, \
dk::util::TermTextColor::color, dk::util::TermTextAttrib::BOLD, \
__VA_ARGS__, \
dk::util::term_text_attrib::DEFAULT
dk::util::TermTextAttrib::DEFAULT

#define DK_LOG_HEADER(color, title, file, func, line) \
"[", DK_LOG_COLOR(color, title), "] ", \
DK_LOG_COLOR(GRAY, dk::log_timestamp{}, " - ", file, "::", func, " (", line, ") - ")
DK_LOG_COLOR(GRAY, dk::LogTimestamp{}, " - ", file, "::", func, " (", line, ") - ")

#define DK_LOG_TITLE(color, title, file, func, line, ...) \
dk::log::print(DK_LOG_HEADER(color, title, file, func, line), __VA_ARGS__)
dk::Log::print(DK_LOG_HEADER(color, title, file, func, line), __VA_ARGS__)

#define DK_LOG_IMPL(file, func, line, ...) DK_LOG_TITLE(LIGHT_BLUE, " MSG ", file, func, line, __VA_ARGS__, '\n')
#define DK_LOG_OK_IMPL(file, func, line, ...) DK_LOG_TITLE(LIGHT_GREEN, " OK! ", file, func, line, __VA_ARGS__, '\n')
Expand All @@ -34,32 +34,32 @@
namespace dk
{

struct log_timestamp {};
struct LogTimestamp {};

class log
class Log
{
private:
static inline std::chrono::steady_clock::time_point s_start; // TODO: inline with plugins? will be 2 instances???

public:
template<typename T> log operator<<(const T& t) const noexcept { std::clog << t; return {}; }
log operator<<(util::term_text_attrib attrib) const noexcept { util::term::set(attrib); return {}; }
log operator<<(util::term_text_color color) const noexcept { util::term::set(color); return {}; }
log operator<<(util::term_back_color color) const noexcept { util::term::set(color); return {}; }
template<typename T> Log operator<<(const T& t) const noexcept { std::clog << t; return {}; }
Log operator<<(util::TermTextAttrib attrib) const noexcept { util::Term::set(attrib); return {}; }
Log operator<<(util::TermTextColor color) const noexcept { util::Term::set(color); return {}; }
Log operator<<(util::TermBackColor color) const noexcept { util::Term::set(color); return {}; }

log operator<<(log_timestamp) const noexcept {
Log operator<<(LogTimestamp) const noexcept {
auto now = std::chrono::steady_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::microseconds>(now - s_start).count();
std::clog << dur / 1000.0f << " ms";
return {};
}

template<typename... Args> static void print(const Args&... args) noexcept { (log{} << ... << args); }
template<typename... Args> static void print(const Args&... args) noexcept { (Log{} << ... << args); }

static status create() noexcept
static Status create() noexcept
{
s_start = std::chrono::steady_clock::now();
return status::OK;
return Status::OK;
}
};

Expand Down
21 changes: 21 additions & 0 deletions include/Mem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef __DK_MEM_H__
#define __DK_MEM_H__

#include <stdlib.h> /* too prevent including of it after defines in this file */
#include "allocs/MemStd.h"

#define mem_alloc(size) Mem::alloc(__FILE__, __func__, __LINE__, size)
#define mem_dealloc(ptr) Mem::dealloc(__FILE__, __func__, __LINE__, ptr)
#define mem_realloc(ptr, size) Mem::realloc(__FILE__, __func__, __LINE__, ptr, size)

#define mem_create(T, ...) Mem::create<T>(__FILE__, __func__, __LINE__ __VA_OPT__(,) __VA_ARGS__)
#define mem_destroy(ptr) Mem::destroy(__FILE__, __func__, __LINE__, ptr)

namespace dk
{

using Mem = MemStd;

}

#endif // !__DK_MEM_H__
8 changes: 4 additions & 4 deletions include/resource.h → include/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace dk
{

enum class resource_type
enum class ResourceType
{
UNKNOWN = 0,
SOUND_DATA,
Expand All @@ -18,12 +18,12 @@ enum class resource_type
ENUM_SIZE
};

class resource
class Resource
{
public:
virtual ~resource() noexcept = default;
virtual ~Resource() noexcept = default;

static resource_type type() noexcept { return resource_type::UNKNOWN; }
static ResourceType type() noexcept { return ResourceType::UNKNOWN; }
};

}
Expand Down
42 changes: 42 additions & 0 deletions include/ResourceGroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef __DK_RESOURCE_GROUP_H__
#define __DK_RESOURCE_GROUP_H__

#include "Resource.h"
#include "containers/Vector.h"
#include "containers/HashTable.h"
#include "containers/StringView.h"

namespace dk
{

class ResourceGroup final: public Resource
{
private:
HashTable<StringView, Resource*> m_res_table;
Vector<Resource*> m_resources;

public:
~ResourceGroup() noexcept override;

Resource* operator[](StringView tag) const noexcept;

bool is_exists(const Resource* res) const noexcept;

void add(Resource* res) noexcept;
void add(Resource* res, StringView tag) noexcept;

bool try_add(Resource* res) noexcept;
bool try_add(Resource* res, StringView tag) noexcept;

void remove(Resource* res) noexcept;
void remove(StringView tag) noexcept;
void remove_all() noexcept;

void destroy(Resource* res) noexcept;
void destroy(StringView tag) noexcept;
void destroy_all() noexcept;
};

}

#endif // !__DK_RESOURCE_GROUP_H__
6 changes: 3 additions & 3 deletions include/status.h → include/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace dk
{

class status
class Status
{
private:
int m_val;
Expand All @@ -15,8 +15,8 @@ class status
static constexpr int ERROR = 2;
static constexpr int FATAL = 3;

constexpr status() noexcept : m_val(OK) {}
constexpr status(int val) noexcept : m_val(val) {}
constexpr Status() noexcept : m_val(OK) {}
constexpr Status(int val) noexcept : m_val(val) {}

constexpr /* explicit */ operator int() const noexcept { return m_val; }
constexpr explicit operator bool() const noexcept { return m_val == OK; }
Expand Down
35 changes: 35 additions & 0 deletions include/allocs/MemStd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef __DK_MEM_STD_H__
#define __DK_MEM_STD_H__

#include <utility>
#include "containers/StringView.h"

namespace dk
{

class MemStd
{
public:
static void* alloc(StringView file, StringView func, size_t line, size_t size) noexcept;
static void dealloc(StringView file, StringView func, size_t line, void* ptr) noexcept;
static void* realloc(StringView file, StringView func, size_t line, void* ptr, size_t new_size) noexcept;

template<typename T, typename... Args>
static T* create(StringView file, StringView func, size_t line, Args&&... args) noexcept
{
return new(alloc(file, func, line, sizeof(T))) T(std::forward<Args>(args)...);
}

template<typename T>
static void destroy(StringView file, StringView func, size_t line, T* t) noexcept
{
if (t != nullptr) {
t->~T();
dealloc(file, func, line, t);
}
}
};

}

#endif // !__DK_MEM_STD_H__
35 changes: 0 additions & 35 deletions include/allocs/mem_std.h

This file was deleted.

6 changes: 3 additions & 3 deletions include/audio/core.h → include/audio/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#define __DK_AUDIO_CORE_H__

#include <AL/alc.h>
#include "status.h"
#include "Status.h"

namespace dk::audio
{

class core
class Core
{
private:
static ALCdevice* s_device;
static ALCcontext* s_context;

public:
static status create() noexcept;
static Status create() noexcept;
static void destroy() noexcept;
};

Expand Down
12 changes: 6 additions & 6 deletions include/audio/debug.h → include/audio/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
#define __DK_AUDIO_DEBUG_H__

#include <AL/al.h>
#include "containers/string_view.h"
#include "log.h"
#include "containers/StringView.h"
#include "Log.h"

#define AL_CALL(func) \
func, \
[](string_view func_name) { \
[](StringView func_name) { \
if(auto err = alGetError(); err != AL_NO_ERROR) \
DK_LOG_ERROR_IMPL(__FILE__, func_name, __LINE__, \
"OpenAL function '", #func, "' failed: ", debug::code_to_str(err)); \
"OpenAL function '", #func, "' failed: ", Debug::code_to_str(err)); \
}(__func__)

namespace dk::audio
{

class debug
class Debug
{
public:
static string_view code_to_str(ALenum code) noexcept;
static StringView code_to_str(ALenum code) noexcept;
};

}
Expand Down
Loading

0 comments on commit 311351f

Please sign in to comment.