Adds iClock interface and its implementations.
This commit is contained in:
parent
b6c35e84a9
commit
1518e429b4
13
Game.h
13
Game.h
@ -6,6 +6,8 @@
|
||||
#include "iDrawable.h"
|
||||
#include "iWritable.h"
|
||||
#include "Logger.h"
|
||||
#include "OffsetClock.h"
|
||||
#include "SystemClock.h"
|
||||
#include "Texture.h"
|
||||
|
||||
|
||||
@ -22,7 +24,8 @@ class Game : public iDrawable, public iWritable {
|
||||
Game& operator=(const Game&) = delete;
|
||||
|
||||
Game(iAllocator* alloc, uint32_t w, uint32_t h) :
|
||||
alloc_(alloc), w_(w), h_(h), logger_(h), test_(Colorbuffer(alloc, 1, 1)) {
|
||||
alloc_(alloc), uptime_(&SystemClock::instance()),
|
||||
w_(w), h_(h), logger_(h), test_(Colorbuffer(alloc, 1, 1)) {
|
||||
Colorbuffer temp(alloc_, 5, 5);
|
||||
float* ptr = temp.ptr();
|
||||
for (size_t i = 0; i < 25; ++i) ptr[i] = i%2*.3+.7;
|
||||
@ -30,11 +33,10 @@ class Game : public iDrawable, public iWritable {
|
||||
}
|
||||
|
||||
void Update() {
|
||||
static int i = 0;
|
||||
++i;
|
||||
if (i%100 == 0) logger_.Print(L"すべての人類は死滅する: "+std::to_wstring(i));
|
||||
const uint64_t i = uptime_.now();
|
||||
if (i%1000 == 0) logger_.Print(L"すべての人類は死滅する: "+std::to_wstring(i));
|
||||
|
||||
double t = i%200/200.;
|
||||
double t = i%2000/2000.;
|
||||
t = 1 - t;
|
||||
|
||||
mat3 m = mat3{ {.2, 0, 0},{0, .2, 0},{0, 0, 1} };
|
||||
@ -55,6 +57,7 @@ class Game : public iDrawable, public iWritable {
|
||||
|
||||
private:
|
||||
iAllocator* alloc_;
|
||||
OffsetClock uptime_;
|
||||
|
||||
uint32_t w_, h_;
|
||||
Logger logger_;
|
||||
|
@ -150,13 +150,16 @@
|
||||
<ClInclude Include="Game.h" />
|
||||
<ClInclude Include="iDrawable.h" />
|
||||
<ClInclude Include="iLogger.h" />
|
||||
<ClInclude Include="iClock.h" />
|
||||
<ClInclude Include="iWritable.h" />
|
||||
<ClInclude Include="Logger.h" />
|
||||
<ClInclude Include="OffsetClock.h" />
|
||||
<ClInclude Include="Rasterbuffer.h" />
|
||||
<ClInclude Include="iConsole.h" />
|
||||
<ClInclude Include="iAllocator.h" />
|
||||
<ClInclude Include="LinearAllocator.h" />
|
||||
<ClInclude Include="StackAllocator.h" />
|
||||
<ClInclude Include="SystemClock.h" />
|
||||
<ClInclude Include="Text.h" />
|
||||
<ClInclude Include="Texture.h" />
|
||||
<ClInclude Include="thirdparty\linalg.h" />
|
||||
|
@ -80,5 +80,14 @@
|
||||
<ClInclude Include="Texture.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="iClock.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SystemClock.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="OffsetClock.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
38
OffsetClock.h
Normal file
38
OffsetClock.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#undef NOMINMAX
|
||||
|
||||
#include "iClock.h"
|
||||
|
||||
namespace gj {
|
||||
|
||||
|
||||
class OffsetClock : public iClock {
|
||||
public:
|
||||
OffsetClock(OffsetClock&&) = default;
|
||||
OffsetClock(const OffsetClock&) = default;
|
||||
|
||||
OffsetClock& operator=(OffsetClock&&) = default;
|
||||
OffsetClock& operator=(const OffsetClock&) = default;
|
||||
|
||||
OffsetClock(const iClock* parent, uint64_t offset) :
|
||||
parent_(parent), offset_(offset) {
|
||||
}
|
||||
OffsetClock(const iClock* parent) : OffsetClock(parent, parent->now()) {
|
||||
}
|
||||
|
||||
uint64_t now() const override {
|
||||
return parent_->now() - offset_;
|
||||
}
|
||||
|
||||
private:
|
||||
const iClock* parent_;
|
||||
uint64_t offset_;
|
||||
};
|
||||
|
||||
|
||||
}
|
35
SystemClock.h
Normal file
35
SystemClock.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#undef NOMINMAX
|
||||
|
||||
#include "iClock.h"
|
||||
|
||||
|
||||
namespace gj {
|
||||
|
||||
|
||||
class SystemClock : public iClock {
|
||||
public:
|
||||
static const SystemClock& instance() {
|
||||
static const SystemClock instance_;
|
||||
return instance_;
|
||||
}
|
||||
|
||||
SystemClock() = default;
|
||||
SystemClock(SystemClock&&) = default;
|
||||
SystemClock(const SystemClock&) = default;
|
||||
|
||||
SystemClock& operator=(SystemClock&&) = default;
|
||||
SystemClock& operator=(const SystemClock&) = default;
|
||||
|
||||
uint64_t now() const override {
|
||||
return GetTickCount64();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
25
iClock.h
Normal file
25
iClock.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace gj {
|
||||
|
||||
|
||||
class iClock {
|
||||
public:
|
||||
iClock() = default;
|
||||
iClock(iClock&&) = default;
|
||||
iClock(const iClock&) = default;
|
||||
|
||||
iClock& operator=(iClock&&) = default;
|
||||
iClock& operator=(const iClock&) = default;
|
||||
|
||||
virtual ~iClock() = default;
|
||||
|
||||
virtual uint64_t now() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user