mirror of https://github.com/auygun/kaliber.git
Cleanup
This commit is contained in:
parent
0398903585
commit
cccc6ca8c3
|
@ -90,10 +90,13 @@ bool Enemy::PreInitialize() {
|
||||||
Engine::Get().SetImageSource("shield_tex", "woom_enemy_shield.png", true);
|
Engine::Get().SetImageSource("shield_tex", "woom_enemy_shield.png", true);
|
||||||
Engine::Get().SetImageSource("crate_tex", "nuke_pack_OK.png", true);
|
Engine::Get().SetImageSource("crate_tex", "nuke_pack_OK.png", true);
|
||||||
|
|
||||||
for (int i = 0; i < kEnemyType_Max; ++i)
|
for (int i = 0; i < kEnemyType_Max; ++i) {
|
||||||
|
if (i == kEnemyType_PowerUp)
|
||||||
|
continue;
|
||||||
Engine::Get().SetImageSource(
|
Engine::Get().SetImageSource(
|
||||||
"score_tex"s + std::to_string(i),
|
"score_tex"s + std::to_string(i),
|
||||||
std::bind(&Enemy::GetScoreImage, this, (EnemyType)i), true);
|
std::bind(&Enemy::GetScoreImage, this, (EnemyType)i), true);
|
||||||
|
}
|
||||||
|
|
||||||
Engine::Get().SetShaderSource("chromatic_aberration",
|
Engine::Get().SetShaderSource("chromatic_aberration",
|
||||||
"chromatic_aberration.glsl");
|
"chromatic_aberration.glsl");
|
||||||
|
@ -647,11 +650,13 @@ void Enemy::SpawnUnit(EnemyType enemy_type,
|
||||||
e.health_bar.PlaceToBottomOf(e.sprite);
|
e.health_bar.PlaceToBottomOf(e.sprite);
|
||||||
e.health_bar.SetColor({0.161f, 0.89f, 0.322f, 1});
|
e.health_bar.SetColor({0.161f, 0.89f, 0.322f, 1});
|
||||||
|
|
||||||
|
if (enemy_type != kEnemyType_PowerUp) {
|
||||||
e.score.Create("score_tex"s + std::to_string(e.enemy_type));
|
e.score.Create("score_tex"s + std::to_string(e.enemy_type));
|
||||||
e.score.SetZOrder(12);
|
e.score.SetZOrder(12);
|
||||||
e.score.Scale(1.1f);
|
e.score.Scale(1.1f);
|
||||||
e.score.SetColor({1, 1, 1, 1});
|
e.score.SetColor({1, 1, 1, 1});
|
||||||
e.score.SetPosition(spawn_pos);
|
e.score.SetPosition(spawn_pos);
|
||||||
|
}
|
||||||
|
|
||||||
e.target_animator.Attach(&e.target);
|
e.target_animator.Attach(&e.target);
|
||||||
|
|
||||||
|
@ -1164,11 +1169,7 @@ int Enemy::GetScore(EnemyType enemy_type) {
|
||||||
std::unique_ptr<Image> Enemy::GetScoreImage(EnemyType enemy_type) {
|
std::unique_ptr<Image> Enemy::GetScoreImage(EnemyType enemy_type) {
|
||||||
const Font& font = static_cast<Demo*>(Engine::Get().GetGame())->GetFont();
|
const Font& font = static_cast<Demo*>(Engine::Get().GetGame())->GetFont();
|
||||||
|
|
||||||
int score = GetScore(enemy_type);
|
std::string text = std::to_string(GetScore(enemy_type));
|
||||||
if (!score)
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
std::string text = std::to_string(score);
|
|
||||||
int width, height;
|
int width, height;
|
||||||
font.CalculateBoundingBox(text.c_str(), width, height);
|
font.CalculateBoundingBox(text.c_str(), width, height);
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,6 @@ void Hud::ShowMessage(const std::string& text, float duration) {
|
||||||
message_text_ = text;
|
message_text_ = text;
|
||||||
Engine::Get().RefreshImage("message");
|
Engine::Get().RefreshImage("message");
|
||||||
|
|
||||||
message_.AutoScale();
|
|
||||||
message_.Scale(1.5f);
|
message_.Scale(1.5f);
|
||||||
message_.SetColor({1, 1, 1, 0});
|
message_.SetColor({1, 1, 1, 0});
|
||||||
message_.SetVisible(true);
|
message_.SetVisible(true);
|
||||||
|
@ -215,7 +214,6 @@ void Hud::ShowMessage(const std::string& text, float duration) {
|
||||||
void Hud::ShowBonus(size_t bonus) {
|
void Hud::ShowBonus(size_t bonus) {
|
||||||
bonus_score_ = bonus;
|
bonus_score_ = bonus;
|
||||||
Engine::Get().RefreshImage("bonus_tex");
|
Engine::Get().RefreshImage("bonus_tex");
|
||||||
bonus_.AutoScale();
|
|
||||||
bonus_.Scale(1.3f);
|
bonus_.Scale(1.3f);
|
||||||
bonus_.SetColor({1, 1, 1, 1});
|
bonus_.SetColor({1, 1, 1, 1});
|
||||||
bonus_.SetVisible(true);
|
bonus_.SetVisible(true);
|
||||||
|
@ -245,26 +243,20 @@ std::unique_ptr<Image> Hud::CreateMessageImage() {
|
||||||
font.Print(x, 0, message_text_.c_str(), image->GetBuffer(),
|
font.Print(x, 0, message_text_.c_str(), image->GetBuffer(),
|
||||||
image->GetWidth());
|
image->GetWidth());
|
||||||
image->Compress();
|
image->Compress();
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Image> Hud::CreateBonusImage() {
|
std::unique_ptr<Image> Hud::CreateBonusImage() {
|
||||||
const Font& font = static_cast<Demo*>(Engine::Get().GetGame())->GetFont();
|
const Font& font = static_cast<Demo*>(Engine::Get().GetGame())->GetFont();
|
||||||
|
|
||||||
if (bonus_score_ == 0)
|
auto image = CreateImage();
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
std::string text = std::to_string(bonus_score_);
|
std::string text = std::to_string(bonus_score_);
|
||||||
int width, height;
|
int w, h;
|
||||||
font.CalculateBoundingBox(text.c_str(), width, height);
|
font.CalculateBoundingBox(text.c_str(), w, h);
|
||||||
|
float x = (image->GetWidth() - w) / 2;
|
||||||
auto image = std::make_unique<Image>();
|
|
||||||
image->Create(width, height);
|
|
||||||
image->Clear({1, 1, 1, 0});
|
|
||||||
|
|
||||||
font.Print(0, 0, text.c_str(), image->GetBuffer(), image->GetWidth());
|
|
||||||
|
|
||||||
|
font.Print(x, 0, text.c_str(), image->GetBuffer(), image->GetWidth());
|
||||||
image->Compress();
|
image->Compress();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
@ -282,7 +274,7 @@ std::unique_ptr<Image> Hud::Print(int i, const std::string& text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
font.Print(x, 0, text.c_str(), image->GetBuffer(), image->GetWidth());
|
font.Print(x, 0, text.c_str(), image->GetBuffer(), image->GetWidth());
|
||||||
|
image->Compress();
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Animatable : public Drawable {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
base::Vector2f position_ = {0, 0};
|
base::Vector2f position_ = {0, 0};
|
||||||
base::Vector2f size_ = {1, 1};
|
base::Vector2f size_ = {0, 0};
|
||||||
base::Vector2f scale_ = {1, 1};
|
base::Vector2f scale_ = {1, 1};
|
||||||
base::Vector2f rotation_ = {0, 1};
|
base::Vector2f rotation_ = {0, 1};
|
||||||
float theta_ = 0;
|
float theta_ = 0;
|
||||||
|
|
|
@ -115,8 +115,6 @@ void Engine::Initialize() {
|
||||||
|
|
||||||
CreateProjectionMatrix();
|
CreateProjectionMatrix();
|
||||||
|
|
||||||
LOG(0) << "image scale factor: " << GetImageScaleFactor();
|
|
||||||
|
|
||||||
system_font_ = std::make_unique<Font>();
|
system_font_ = std::make_unique<Font>();
|
||||||
system_font_->Load("engine/RobotoMono-Regular.ttf");
|
system_font_->Load("engine/RobotoMono-Regular.ttf");
|
||||||
|
|
||||||
|
@ -148,10 +146,8 @@ void Engine::Update(float delta_time) {
|
||||||
fps_seconds_ = 0;
|
fps_seconds_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stats_->IsVisible()) {
|
if (stats_->IsVisible())
|
||||||
RefreshImage("stats_tex");
|
RefreshImage("stats_tex");
|
||||||
stats_->AutoScale();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::Draw(float frame_frac) {
|
void Engine::Draw(float frame_frac) {
|
||||||
|
@ -454,14 +450,8 @@ int Engine::GetScreenHeight() const {
|
||||||
return renderer_->GetScreenHeight();
|
return renderer_->GetScreenHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Engine::GetDeviceDpi() const {
|
|
||||||
return platform_->GetDeviceDpi();
|
|
||||||
}
|
|
||||||
|
|
||||||
float Engine::GetImageScaleFactor() const {
|
float Engine::GetImageScaleFactor() const {
|
||||||
float width_inch = static_cast<float>(renderer_->GetScreenWidth()) /
|
return static_cast<float>(renderer_->GetScreenWidth()) / 514.286f;
|
||||||
static_cast<float>(platform_->GetDeviceDpi());
|
|
||||||
return 2.57143f / width_inch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Engine::GetRootPath() const {
|
const std::string& Engine::GetRootPath() const {
|
||||||
|
@ -605,17 +595,11 @@ void Engine::CreateTextureCompressors() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::CreateProjectionMatrix() {
|
void Engine::CreateProjectionMatrix() {
|
||||||
if (GetScreenWidth() > GetScreenHeight()) {
|
|
||||||
float aspect_ratio = (float)GetScreenWidth() / (float)GetScreenHeight();
|
|
||||||
LOG(0) << "aspect ratio: " << aspect_ratio;
|
|
||||||
screen_size_ = {aspect_ratio * 2.0f, 2.0f};
|
|
||||||
projection_.CreateOrthoProjection(-aspect_ratio, aspect_ratio, -1.0f, 1.0f);
|
|
||||||
} else {
|
|
||||||
float aspect_ratio = (float)GetScreenHeight() / (float)GetScreenWidth();
|
float aspect_ratio = (float)GetScreenHeight() / (float)GetScreenWidth();
|
||||||
LOG(0) << "aspect_ratio: " << aspect_ratio;
|
LOG(0) << "aspect_ratio: " << aspect_ratio;
|
||||||
screen_size_ = {2.0f, aspect_ratio * 2.0f};
|
screen_size_ = {1.0f, aspect_ratio * 1.0f};
|
||||||
projection_.CreateOrthoProjection(-1.0, 1.0, -aspect_ratio, aspect_ratio);
|
projection_.CreateOrthoProjection(-0.5f, 0.5f, -aspect_ratio * 0.5f,
|
||||||
}
|
aspect_ratio * 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::ContextLost() {
|
void Engine::ContextLost() {
|
||||||
|
|
|
@ -99,8 +99,6 @@ class Engine : public PlatformObserver {
|
||||||
|
|
||||||
void SetKeepScreenOn(bool keep_screen_on);
|
void SetKeepScreenOn(bool keep_screen_on);
|
||||||
|
|
||||||
void SetImageDpi(float dpi) { image_dpi_ = dpi; }
|
|
||||||
|
|
||||||
void SetEnableAudio(bool enable);
|
void SetEnableAudio(bool enable);
|
||||||
|
|
||||||
void SetEnableVibration(bool enable) { vibration_enabled_ = enable; }
|
void SetEnableVibration(bool enable) { vibration_enabled_ = enable; }
|
||||||
|
@ -129,8 +127,6 @@ class Engine : public PlatformObserver {
|
||||||
|
|
||||||
const base::Matrix4f& GetProjectionMatrix() const { return projection_; }
|
const base::Matrix4f& GetProjectionMatrix() const { return projection_; }
|
||||||
|
|
||||||
int GetDeviceDpi() const;
|
|
||||||
|
|
||||||
float GetImageScaleFactor() const;
|
float GetImageScaleFactor() const;
|
||||||
|
|
||||||
const std::string& GetRootPath() const;
|
const std::string& GetRootPath() const;
|
||||||
|
@ -145,8 +141,6 @@ class Engine : public PlatformObserver {
|
||||||
|
|
||||||
float seconds_accumulated() const { return seconds_accumulated_; }
|
float seconds_accumulated() const { return seconds_accumulated_; }
|
||||||
|
|
||||||
float image_dpi() const { return image_dpi_; }
|
|
||||||
|
|
||||||
float time_step() { return time_step_; }
|
float time_step() { return time_step_; }
|
||||||
|
|
||||||
int fps() const { return fps_; }
|
int fps() const { return fps_; }
|
||||||
|
@ -207,8 +201,6 @@ class Engine : public PlatformObserver {
|
||||||
float time_step_ = 1.0f / 60.0f;
|
float time_step_ = 1.0f / 60.0f;
|
||||||
size_t tick_ = 0;
|
size_t tick_ = 0;
|
||||||
|
|
||||||
float image_dpi_ = 200;
|
|
||||||
|
|
||||||
bool vibration_enabled_ = true;
|
bool vibration_enabled_ = true;
|
||||||
|
|
||||||
std::deque<std::unique_ptr<InputEvent>> input_queue_;
|
std::deque<std::unique_ptr<InputEvent>> input_queue_;
|
||||||
|
|
|
@ -21,15 +21,15 @@ void ImageQuad::Create(const std::string& asset_name,
|
||||||
int frame_width,
|
int frame_width,
|
||||||
int frame_height) {
|
int frame_height) {
|
||||||
texture_ = Engine::Get().AcquireTexture(asset_name);
|
texture_ = Engine::Get().AcquireTexture(asset_name);
|
||||||
|
|
||||||
num_frames_ = std::move(num_frames);
|
num_frames_ = std::move(num_frames);
|
||||||
frame_width_ = frame_width;
|
frame_width_ = frame_width;
|
||||||
frame_height_ = frame_height;
|
frame_height_ = frame_height;
|
||||||
|
|
||||||
if ((frame_width_ > 0 && frame_height_ > 0) || texture_->IsValid())
|
|
||||||
AutoScale();
|
|
||||||
|
|
||||||
asset_name_ = asset_name;
|
asset_name_ = asset_name;
|
||||||
|
|
||||||
|
DCHECK((frame_width_ > 0 && frame_height_ > 0) || texture_->IsValid())
|
||||||
|
<< asset_name;
|
||||||
|
SetSize(Engine::Get().ToScale({GetFrameWidth(), GetFrameHeight()}) *
|
||||||
|
Engine::Get().GetImageScaleFactor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageQuad::Destroy() {
|
void ImageQuad::Destroy() {
|
||||||
|
@ -39,16 +39,6 @@ void ImageQuad::Destroy() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageQuad::AutoScale() {
|
|
||||||
auto& engine = Engine::Get();
|
|
||||||
Vector2f dimensions = {GetFrameWidth(), GetFrameHeight()};
|
|
||||||
Vector2f size = engine.ToScale(dimensions);
|
|
||||||
float s =
|
|
||||||
static_cast<float>(engine.image_dpi()) * engine.GetImageScaleFactor();
|
|
||||||
size *= static_cast<float>(engine.GetDeviceDpi()) / s;
|
|
||||||
SetSize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImageQuad::SetCustomShader(const std::string& asset_name) {
|
void ImageQuad::SetCustomShader(const std::string& asset_name) {
|
||||||
custom_shader_ = Engine::Get().GetShader(asset_name);
|
custom_shader_ = Engine::Get().GetShader(asset_name);
|
||||||
custom_uniforms_.clear();
|
custom_uniforms_.clear();
|
||||||
|
|
|
@ -26,8 +26,6 @@ class ImageQuad final : public Animatable {
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
void AutoScale();
|
|
||||||
|
|
||||||
void SetCustomShader(const std::string& asset_name);
|
void SetCustomShader(const std::string& asset_name);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
Loading…
Reference in New Issue