0.7.0 rewrite dev
- remove everyting - keep core -rename bit_utils to bits - add formatter for color - add float getters to color - start with new drivers api
This commit is contained in:
76
source/core/bit_util.cpp → source/core/bits.cpp
Executable file → Normal file
76
source/core/bit_util.cpp → source/core/bits.cpp
Executable file → Normal file
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/bit_util.hpp>
|
||||
|
||||
namespace PD::BitUtil {
|
||||
PD_API bool IsSingleBit(u32 v) { return v && !(v & (v - 1)); }
|
||||
PD_API u32 GetPow2(u32 v) {
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return (v >= 64 ? v : 64);
|
||||
}
|
||||
} // namespace PD::BitUtil
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/bits.hpp>
|
||||
|
||||
namespace PD::Bits {
|
||||
PD_API bool IsSingleBit(u32 v) { return v && !(v & (v - 1)); }
|
||||
PD_API u32 GetPow2(u32 v) {
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return (v >= 64 ? v : 64);
|
||||
}
|
||||
} // namespace PD::Bits
|
||||
@@ -26,14 +26,10 @@ SOFTWARE.
|
||||
namespace PD {
|
||||
PD_API std::string Color::Hex(bool rgba) const {
|
||||
/** Need to int cast (so it is used as num and not char...) */
|
||||
std::stringstream s;
|
||||
s << "#";
|
||||
s << std::hex << std::setw(2) << std::setfill('0') << (int)r;
|
||||
s << std::hex << std::setw(2) << std::setfill('0') << (int)g;
|
||||
s << std::hex << std::setw(2) << std::setfill('0') << (int)b;
|
||||
std::string ret = std::format("#{:02X}{:02X}{:02X}", r, g, b);
|
||||
if (rgba || a != 255) { // QoL change btw
|
||||
s << std::hex << std::setw(2) << std::setfill('0') << (int)a;
|
||||
ret += std::format("{:02X}", a);
|
||||
}
|
||||
return s.str();
|
||||
return ret;
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -22,22 +22,25 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/timer.hpp>
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD_API Timer::Timer(OsDriver& os, bool autostart) : pOs(os) {
|
||||
PD_API Timer::Timer(bool autostart) {
|
||||
pIsRunning = autostart;
|
||||
Reset();
|
||||
}
|
||||
|
||||
PD_API void Timer::Reset() {
|
||||
pStart = pOs.GetTime();
|
||||
pStart = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count();
|
||||
pNow = pStart;
|
||||
}
|
||||
|
||||
PD_API void Timer::Update() {
|
||||
if (pIsRunning) {
|
||||
pNow = pOs.GetTime();
|
||||
pNow = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch())
|
||||
.count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,15 +22,14 @@ SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/timetrace.hpp>
|
||||
#include <pd/drivers/drivers.hpp>
|
||||
|
||||
namespace PD::TT {
|
||||
PD_API void Beg(OsDriver& os, const std::string& id) {
|
||||
PD_API void Beg(const std::string& id) {
|
||||
auto trace = os.GetTraceRef(id);
|
||||
trace->SetStart(os.GetNanoTime());
|
||||
}
|
||||
|
||||
PD_API void End(OsDriver& os, const std::string& id) {
|
||||
PD_API void End(const std::string& id) {
|
||||
auto trace = os.GetTraceRef(id);
|
||||
trace->SetEnd(os.GetNanoTime());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user