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("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(
|
||||
"score_tex"s + std::to_string(i),
|
||||
std::bind(&Enemy::GetScoreImage, this, (EnemyType)i), true);
|
||||
}
|
||||
|
||||
Engine::Get().SetShaderSource("chromatic_aberration",
|
||||
"chromatic_aberration.glsl");
|
||||
|
@ -647,11 +650,13 @@ void Enemy::SpawnUnit(EnemyType enemy_type,
|
|||
e.health_bar.PlaceToBottomOf(e.sprite);
|
||||
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.SetZOrder(12);
|
||||
e.score.Scale(1.1f);
|
||||
e.score.SetColor({1, 1, 1, 1});
|
||||
e.score.SetPosition(spawn_pos);
|
||||
}
|
||||
|
||||
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) {
|
||||
const Font& font = static_cast<Demo*>(Engine::Get().GetGame())->GetFont();
|
||||
|
||||
int score = GetScore(enemy_type);
|
||||
if (!score)
|
||||
return nullptr;
|
||||
|
||||
std::string text = std::to_string(score);
|
||||
std::string text = std::to_string(GetScore(enemy_type));
|
||||
int 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;
|
||||
Engine::Get().RefreshImage("message");
|
||||
|
||||
message_.AutoScale();
|
||||
message_.Scale(1.5f);
|
||||
message_.SetColor({1, 1, 1, 0});
|
||||
message_.SetVisible(true);
|
||||
|
@ -215,7 +214,6 @@ void Hud::ShowMessage(const std::string& text, float duration) {
|
|||
void Hud::ShowBonus(size_t bonus) {
|
||||
bonus_score_ = bonus;
|
||||
Engine::Get().RefreshImage("bonus_tex");
|
||||
bonus_.AutoScale();
|
||||
bonus_.Scale(1.3f);
|
||||
bonus_.SetColor({1, 1, 1, 1});
|
||||
bonus_.SetVisible(true);
|
||||
|
@ -245,26 +243,20 @@ std::unique_ptr<Image> Hud::CreateMessageImage() {
|
|||
font.Print(x, 0, message_text_.c_str(), image->GetBuffer(),
|
||||
image->GetWidth());
|
||||
image->Compress();
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
std::unique_ptr<Image> Hud::CreateBonusImage() {
|
||||
const Font& font = static_cast<Demo*>(Engine::Get().GetGame())->GetFont();
|
||||
|
||||
if (bonus_score_ == 0)
|
||||
return nullptr;
|
||||
auto image = CreateImage();
|
||||
|
||||
std::string text = std::to_string(bonus_score_);
|
||||
int width, height;
|
||||
font.CalculateBoundingBox(text.c_str(), width, height);
|
||||
|
||||
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());
|
||||
int w, h;
|
||||
font.CalculateBoundingBox(text.c_str(), w, h);
|
||||
float x = (image->GetWidth() - w) / 2;
|
||||
|
||||
font.Print(x, 0, text.c_str(), image->GetBuffer(), image->GetWidth());
|
||||
image->Compress();
|
||||
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());
|
||||
|
||||
image->Compress();
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class Animatable : public Drawable {
|
|||
|
||||
protected:
|
||||
base::Vector2f position_ = {0, 0};
|
||||
base::Vector2f size_ = {1, 1};
|
||||
base::Vector2f size_ = {0, 0};
|
||||
base::Vector2f scale_ = {1, 1};
|
||||
base::Vector2f rotation_ = {0, 1};
|
||||
float theta_ = 0;
|
||||
|
|
|
@ -115,8 +115,6 @@ void Engine::Initialize() {
|
|||
|
||||
CreateProjectionMatrix();
|
||||
|
||||
LOG(0) << "image scale factor: " << GetImageScaleFactor();
|
||||
|
||||
system_font_ = std::make_unique<Font>();
|
||||
system_font_->Load("engine/RobotoMono-Regular.ttf");
|
||||
|
||||
|
@ -148,10 +146,8 @@ void Engine::Update(float delta_time) {
|
|||
fps_seconds_ = 0;
|
||||
}
|
||||
|
||||
if (stats_->IsVisible()) {
|
||||
if (stats_->IsVisible())
|
||||
RefreshImage("stats_tex");
|
||||
stats_->AutoScale();
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::Draw(float frame_frac) {
|
||||
|
@ -454,14 +450,8 @@ int Engine::GetScreenHeight() const {
|
|||
return renderer_->GetScreenHeight();
|
||||
}
|
||||
|
||||
int Engine::GetDeviceDpi() const {
|
||||
return platform_->GetDeviceDpi();
|
||||
}
|
||||
|
||||
float Engine::GetImageScaleFactor() const {
|
||||
float width_inch = static_cast<float>(renderer_->GetScreenWidth()) /
|
||||
static_cast<float>(platform_->GetDeviceDpi());
|
||||
return 2.57143f / width_inch;
|
||||
return static_cast<float>(renderer_->GetScreenWidth()) / 514.286f;
|
||||
}
|
||||
|
||||
const std::string& Engine::GetRootPath() const {
|
||||
|
@ -605,17 +595,11 @@ void Engine::CreateTextureCompressors() {
|
|||
}
|
||||
|
||||
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();
|
||||
LOG(0) << "aspect_ratio: " << aspect_ratio;
|
||||
screen_size_ = {2.0f, aspect_ratio * 2.0f};
|
||||
projection_.CreateOrthoProjection(-1.0, 1.0, -aspect_ratio, aspect_ratio);
|
||||
}
|
||||
screen_size_ = {1.0f, aspect_ratio * 1.0f};
|
||||
projection_.CreateOrthoProjection(-0.5f, 0.5f, -aspect_ratio * 0.5f,
|
||||
aspect_ratio * 0.5f);
|
||||
}
|
||||
|
||||
void Engine::ContextLost() {
|
||||
|
|
|
@ -99,8 +99,6 @@ class Engine : public PlatformObserver {
|
|||
|
||||
void SetKeepScreenOn(bool keep_screen_on);
|
||||
|
||||
void SetImageDpi(float dpi) { image_dpi_ = dpi; }
|
||||
|
||||
void SetEnableAudio(bool enable);
|
||||
|
||||
void SetEnableVibration(bool enable) { vibration_enabled_ = enable; }
|
||||
|
@ -129,8 +127,6 @@ class Engine : public PlatformObserver {
|
|||
|
||||
const base::Matrix4f& GetProjectionMatrix() const { return projection_; }
|
||||
|
||||
int GetDeviceDpi() const;
|
||||
|
||||
float GetImageScaleFactor() const;
|
||||
|
||||
const std::string& GetRootPath() const;
|
||||
|
@ -145,8 +141,6 @@ class Engine : public PlatformObserver {
|
|||
|
||||
float seconds_accumulated() const { return seconds_accumulated_; }
|
||||
|
||||
float image_dpi() const { return image_dpi_; }
|
||||
|
||||
float time_step() { return time_step_; }
|
||||
|
||||
int fps() const { return fps_; }
|
||||
|
@ -207,8 +201,6 @@ class Engine : public PlatformObserver {
|
|||
float time_step_ = 1.0f / 60.0f;
|
||||
size_t tick_ = 0;
|
||||
|
||||
float image_dpi_ = 200;
|
||||
|
||||
bool vibration_enabled_ = true;
|
||||
|
||||
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_height) {
|
||||
texture_ = Engine::Get().AcquireTexture(asset_name);
|
||||
|
||||
num_frames_ = std::move(num_frames);
|
||||
frame_width_ = frame_width;
|
||||
frame_height_ = frame_height;
|
||||
|
||||
if ((frame_width_ > 0 && frame_height_ > 0) || texture_->IsValid())
|
||||
AutoScale();
|
||||
|
||||
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() {
|
||||
|
@ -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) {
|
||||
custom_shader_ = Engine::Get().GetShader(asset_name);
|
||||
custom_uniforms_.clear();
|
||||
|
|
|
@ -26,8 +26,6 @@ class ImageQuad final : public Animatable {
|
|||
|
||||
void Destroy();
|
||||
|
||||
void AutoScale();
|
||||
|
||||
void SetCustomShader(const std::string& asset_name);
|
||||
|
||||
template <typename T>
|
||||
|
|
Loading…
Reference in New Issue