添加批量drawcall

This commit is contained in:
2025-05-19 16:22:34 +08:00
parent f6ccb823c7
commit e67a193c77
58 changed files with 1358 additions and 162 deletions

View File

@ -0,0 +1,59 @@
//
// Created by sfd on 25-5-18.
//
#include "GameLayer.h"
#include <imgui_internal.h>
#include <Hazel/Core/Application.h>
GameLayer::GameLayer() : Layer("GameLayer")
{
auto& window = Application::Get().GetWindow();
CreateCamera(window.GetWidth(), window.GetHeight());
Random::Init();
}
void GameLayer::OnAttach()
{
m_Level.Init();
ImGuiIO& io = ImGui::GetIO();
}
void GameLayer::OnDetech()
{
}
void GameLayer::OnUpdate(TimeStep& ts)
{
m_Time += ts;
}
void GameLayer::OnEvent(SDL_Event& e)
{
if (const auto& window = Application::Get().GetWindow(); e.type == SDL_EVENT_WINDOW_RESIZED && e.window.windowID == window.GetMainWindowID())
{
CreateCamera(window.GetWidth(), window.GetHeight());
}
}
void GameLayer::OnImGuiRender()
{
}
void GameLayer::CreateCamera(uint32_t width, uint32_t height)
{
const float aspect = static_cast<float>(width) / static_cast<float>(height);
const float camWidth = 8.0f;
const float bottom = -camWidth;
const float top = camWidth;
const float left = bottom * aspect;
const float right = top * aspect;
m_Camera = OrthographicCamera(left, right, bottom, top);
}

View File

@ -0,0 +1,43 @@
//
// Created by sfd on 25-5-18.
//
#ifndef GAMELAYER_H
#define GAMELAYER_H
#include <Hazel/Core/Layer.h>
#include <Hazel/Renderer/OrthographicCamera.h>
#include "Random.h"
using namespace Hazel;
class GameLayer : public Layer{
public:
GameLayer();
~GameLayer() = default;
void OnAttach() override;
void OnDetech() override;
void OnUpdate(TimeStep& ts) override;
void OnEvent(SDL_Event& e) override;
void OnImGuiRender() override;
void CreateCamera(uint32_t width, uint32_t height);
private:
std::unique_ptr<OrthographicCamera> m_Camera;
float m_Time = 0.0f;
bool m_Blink = false;
enum class GameState
{
Play = 0, MainMenu, GameOver
};
GameState m_GameState = GameState::MainMenu;
};
#endif //GAMELAYER_H

View File

@ -0,0 +1,5 @@
//
// Created by sfd on 25-5-18.
//
#include "Random.h"

View File

@ -0,0 +1,28 @@
//
// Created by sfd on 25-5-18.
//
#ifndef RANDOM_H
#define RANDOM_H
#include <random>
class Random {
public:
static void Init() {
s_RandomEngine.seed(std::random_device()());
}
static float Float()
{
return (float)s_Distribution(s_RandomEngine) / (float)std::numeric_limits<uint32_t>::max();
}
private:
static std::mt19937 s_RandomEngine;
static std::uniform_int_distribution<std::mt19937::result_type> s_Distribution;
};
#endif //RANDOM_H