Skip to content

Commit

Permalink
AAAAAAAA METAINFO DONEgit status! AAAAAAAAAA
Browse files Browse the repository at this point in the history
  • Loading branch information
UtoECat committed Feb 20, 2024
1 parent e012766 commit 805cde8
Show file tree
Hide file tree
Showing 32 changed files with 2,447 additions and 893 deletions.
1 change: 0 additions & 1 deletion .clang

This file was deleted.

3 changes: 3 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
CompileFlags:
Add: [-I. -fanalyze]
6 changes: 1 addition & 5 deletions base/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* Please use compiler with C++20 concepts and general C++20 support to compile pixelbox!
*/

#include <iterator>
#include <stdexcept>
#if !((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L || PB_NO_STDVER_CHECK)
#error C++17 support is required!
#endif
Expand All @@ -37,7 +35,6 @@

#include <stdint.h>
#include <limits.h>
#include <string>

namespace pb {

Expand Down Expand Up @@ -76,7 +73,6 @@ namespace pb {
};

/** @deprecated */
class Default : public Static {};

/** Abstract base class */
class Abstract {
Expand All @@ -97,4 +93,4 @@ namespace pb {
#define ANONYMOUS(x) CONCAT(x, __COUNTER__)
#else // __COUNTER__
#define ANONYMOUS(x) CONCAT(x, __LINE__)
#endif // __COUNTER__
#endif // __COUNTER__
48 changes: 25 additions & 23 deletions base/event.hpp → base/defer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is a part of Pixelbox - Infinite 2D sandbox game
* Evenst for objservers/subscribers patterns
* Guaranteed execution of destructor, for RAII
* Copyright (C) 2023-2024 UtoECat
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -18,33 +18,35 @@
*/

#pragma once
#include <functional>
#include <type_traits>
#include <utility>
#include "base/base.hpp"

namespace pb {

// subject for "Observers"
// TODO : This thing is horrible...
template <typename F, typename... Args>
class Subject {
protected:
using function_type = std::function<F(Args...)>;
std::vector<function_type> handlers;
public:
Subject() {};
Subject(const Subject&) = default;
Subject(Subject&&) = default;
Subject& operator=(const Subject&) = default;
Subject& operator=(Subject&&) = default;
void subscribe(const function_type& f) { handlers.emplace_back(f); }
void subscribe(function_type&& f) { handlers.emplace_back(std::move(f)); }
void notify_all(Args&&... args) {
for (auto& f : handlers) {
f(std::forward<Args>(args)...);
}
}
};
namespace impl {

template <class F>
class ScopeGuard : Moveable {
private:
F f;
bool invoke = true;
public:
explicit ScopeGuard(const F& ff) : f(ff) { }
explicit ScopeGuard(F&& ff) : f(std::move(ff)) { }
~ScopeGuard() { if (invoke) f(); }
ScopeGuard(ScopeGuard&& other) noexcept : f(std::move(other.f)) {
other.invoke = false;
}
ScopeGuard(const ScopeGuard&&) = delete;
};

};

// defer operator :D yay
template <class F>
[[nodiscard]] auto defer(F&& f) noexcept {
return impl::ScopeGuard<std::decay_t<F>>{std::forward<F>(f)};
}

};
15 changes: 1 addition & 14 deletions base/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@
*/

#include "profiler.hpp"
#include "base/base.hpp"
#include "clock.hpp"

#include "spinlock.hpp"
#include "base/resource.hpp"

#include <memory>
#include <stdexcept>
#include <thread>
#include <mutex>

#include <array>
#include <stack>
#include <utility>
#include <stdexcept>
Expand Down Expand Up @@ -338,15 +334,6 @@ void ThreadData::begin(const HString& name) {
void ThreadData::end() {return data.end();}
void ThreadData::step() {return data.step();}

/** syntax sugar and safer wrapper of begin()/end() functions above
* Calls begin() immediatly, and calls end when returned object is destructed
*/
ScopeGuard<void()> ThreadData::make_zone(const HString& name) {
begin(name);
auto &master = *this;
return ScopeGuard<void()>([&master]{master.end();});
}

/**
* API for retrieving profiling results
*/
Expand Down Expand Up @@ -414,4 +401,4 @@ size_t get_current_position(ThreadID id) {

};

};
};
16 changes: 10 additions & 6 deletions base/profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#pragma once
#include "base/base.hpp"
#include "base/string.hpp"
#include "base/scopeguard.hpp"
#include "base/defer.hpp"

#include <map> // insertion speed and reference stablility matters here
#include <thread> // for ThreadID
Expand Down Expand Up @@ -86,12 +86,16 @@ class ThreadData {
* done.~~ This requirement is removed in current version : you can safely
* tick in the middle of deep zone stack :)
*/
void step();
void step();

/** syntax sugar and safer wrapper of begin()/end() functions above
/** syntax sugar and safer wrapper of begin()/end() functions above
* Calls begin() immediatly, and calls end when returned object is destructed
*/
pb::ScopeGuard<void()> make_zone(const HString& name);
auto make_zone(const HString& name) {
begin(name);
auto &master = *this;
return pb::defer([&master]{master.end();});
}
};

/**
Expand All @@ -108,9 +112,9 @@ void free_thread_data(ThreadData);
ThreadData get_thread_data();

/** convinient wrapper around initialization things above */
inline pb::ScopeGuard<void()> make_thread_data() {
inline auto make_thread_data() {
ThreadData data = init_thread_data();
return pb::ScopeGuard<void()> ([data]() {
return pb::defer([data]() {
free_thread_data(data);
});
}
Expand Down
2 changes: 1 addition & 1 deletion base/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ functions/libraries/systems all over the place :
- locale-independent strtod()

# todo
- ~~Locale and implementation-independent vsnprintf() :p~~(done)
- ~~Locale and implementation-independent vsnprintf() :p~~(done)
2 changes: 1 addition & 1 deletion base/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ class Resource<T, void> : public T{
ResUsage<T, void> use() {
return {static_cast<T&>(*this)};
}
};
};
66 changes: 0 additions & 66 deletions base/scopeguard.hpp

This file was deleted.

2 changes: 0 additions & 2 deletions base/sharedobj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/

#pragma once
#include "base.hpp"
#include "spinlock.hpp"
#include <memory>

namespace pb {
Expand Down
1 change: 0 additions & 1 deletion base/spinlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#pragma once
#include <atomic>
#include <mutex>
#include <thread>

namespace pb {

Expand Down
8 changes: 7 additions & 1 deletion base/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once
#include <string>
#include <stdexcept>
#include <string_view>
#include "external/printf.h"

namespace pb {
Expand Down Expand Up @@ -108,6 +109,7 @@ namespace pb {
auto size = static_cast<size_t>(size_s + 1); // Extra space for '\0'
result.resize(size);
auto vv = snprintf_( &result[0], size, format.c_str(), args... );
result.pop_back(); // remove '\0!'
return (vv > 0);
}

Expand All @@ -131,6 +133,10 @@ namespace pb {
*/
double strtod(const char *str, char **end);


using String = std::string;
using StringView = std::string_view;

};

// here is the hash function
Expand All @@ -142,4 +148,4 @@ struct std::hash<pb::HString> {
std::size_t operator()(const pb::HString& s) const noexcept {
return s.get_hash();
}
};
};
2 changes: 0 additions & 2 deletions base/strtod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
* modified a bit by utoecat. still public domain.
*/

#include "base/base.hpp"
#include <string.h>
#include <math.h>
#include <ctype.h>

Expand Down
Loading

0 comments on commit 805cde8

Please sign in to comment.