This repository has been archived on 2022-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
glyphs-juke/Game.h

69 lines
1.6 KiB
C++

#pragma once
#include <cmath>
#include <string>
#include "iDrawable.h"
#include "iWritable.h"
#include "Logger.h"
#include "OffsetClock.h"
#include "SystemClock.h"
#include "Texture.h"
namespace gj {
class Game : public iDrawable, public iWritable {
public:
Game() = delete;
Game(Game&&) = delete;
Game(const Game&) = delete;
Game& operator=(Game&&) = delete;
Game& operator=(const Game&) = delete;
Game(iAllocator* alloc, uint32_t w, uint32_t h) :
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;
test_ = Texture(std::move(temp));
}
void Update() {
const uint64_t i = uptime_.now();
if (i%1000 == 0) logger_.Print(L"すべての人類は死滅する: "+std::to_wstring(i));
double t = i%2000/2000.;
t = 1 - t;
mat3 m = mat3{ {.2, 0, 0},{0, .2, 0},{0, 0, 1} };
const double s = sin(3.14*2*t*t*t), c = cos(3.14*2*t*t*t);
m = ::linalg::mul(mat3{{c, -s, 0,}, {s, c, 0}, {0, 0, 1}}, m);
m = ::linalg::mul(mat3{{ 1, 0, 0,}, {0, 1, 0}, {(1 - t * t * t * 2) * .6, 0, 1}}, m);
m = ::linalg::mul(mat3{ {1, 0, 0},{0, 16/9., 0},{0, 0, 1} }, m);
test_.SetMatrix(m);
}
void Draw(Colorbuffer& fb) const override {
test_.Draw(fb);
}
void Write(Textbuffer& fb) const override {
logger_.Write(fb);
}
private:
iAllocator* alloc_;
OffsetClock uptime_;
uint32_t w_, h_;
Logger logger_;
Texture test_;
};
}