统一 Image 和 Sprite 语义到目前的 Image/Sprite 结构体而非之前的类定义
This commit is contained in:
+166687
-166687
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
||||
#include "Color.h"
|
||||
#include "DrawContext.h"
|
||||
#include "PointerInput.h"
|
||||
#include "SpriteRegion.h"
|
||||
#include "Sprite.h"
|
||||
#include "tom_atlas.h"
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
@@ -19,7 +19,7 @@ namespace
|
||||
const int32_t TomBottomPadding = 72;
|
||||
const int32_t ButtonBottomPadding = 16;
|
||||
|
||||
const RenderData::SpriteRegion* const SpeakingFrames[] = {
|
||||
const RenderData::Sprite* const SpeakingFrames[] = {
|
||||
&TomAtlas::tom_say1,
|
||||
&TomAtlas::tom_say2,
|
||||
&TomAtlas::tom_say3,
|
||||
@@ -28,7 +28,7 @@ namespace
|
||||
&TomAtlas::tom_say2
|
||||
};
|
||||
|
||||
static const RenderData::SpriteRegion& SelectSpeakingFrame(uint32_t animationMs)
|
||||
static const RenderData::Sprite& SelectSpeakingFrame(uint32_t animationMs)
|
||||
{
|
||||
const size_t frameCount = sizeof(SpeakingFrames) / sizeof(SpeakingFrames[0]);
|
||||
const size_t frameIndex = (animationMs / SpeakingFrameMs) % frameCount;
|
||||
@@ -113,9 +113,9 @@ namespace Game
|
||||
void TomGameApp::draw(Core::DrawContext& ctx)
|
||||
{
|
||||
ctx.clear_color(RenderData::Color(18, 18, 24, 255));
|
||||
ctx.draw_sprite_region(0, 0, TomAtlas::background);
|
||||
ctx.draw_sprite(0, 0, TomAtlas::background);
|
||||
|
||||
const RenderData::SpriteRegion* tom = &TomAtlas::tom_stand;
|
||||
const RenderData::Sprite* tom = &TomAtlas::tom_stand;
|
||||
if (state == TomGameState::Recording)
|
||||
{
|
||||
tom = &TomAtlas::tom_listhen;
|
||||
@@ -132,8 +132,8 @@ namespace Game
|
||||
tomY = 0;
|
||||
}
|
||||
|
||||
ctx.draw_sprite_region(tomX, tomY, *tom);
|
||||
ctx.draw_sprite_region(buttonX, buttonY, TomAtlas::ui_record);
|
||||
ctx.draw_sprite(tomX, tomY, *tom);
|
||||
ctx.draw_sprite(buttonX, buttonY, TomAtlas::ui_record);
|
||||
}
|
||||
|
||||
void TomGameApp::update_input(bool& recordTrigger)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "AnimationSystem.h"
|
||||
#include "SpriteRasterizer.h"
|
||||
#include "DrawContext.h"
|
||||
|
||||
namespace Game
|
||||
{
|
||||
@@ -35,7 +35,7 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationSystem::draw(Rasterizer::SpriteRasterizer& spriteRasterizer) const
|
||||
void AnimationSystem::draw(Core::DrawContext& drawContext) const
|
||||
{
|
||||
for (size_t i = 0; i < objects.size(); ++i)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ namespace Game
|
||||
const RenderData::Sprite* sprite = object.animator->get_current_sprite();
|
||||
if (sprite != nullptr)
|
||||
{
|
||||
spriteRasterizer.DrawSprite(*sprite, object.x, object.y);
|
||||
drawContext.draw_sprite(object.x, object.y, *sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <vector>
|
||||
#include "../components/SpriteAnimator.h"
|
||||
|
||||
namespace Rasterizer
|
||||
namespace Core
|
||||
{
|
||||
class SpriteRasterizer;
|
||||
class DrawContext;
|
||||
}
|
||||
|
||||
namespace Game
|
||||
@@ -38,7 +38,7 @@ namespace Game
|
||||
void clear();
|
||||
|
||||
void update(float deltaTime);
|
||||
void draw(Rasterizer::SpriteRasterizer& spriteRasterizer) const;
|
||||
void draw(Core::DrawContext& drawContext) const;
|
||||
|
||||
void set_position(size_t index, int32_t x, int32_t y);
|
||||
void set_visible(size_t index, bool visible);
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace
|
||||
const std::vector<uint16_t>& atlas_pixels,
|
||||
int32_t atlas_height)
|
||||
{
|
||||
std::ofstream file(OutputHeaderPath);
|
||||
std::ofstream file(OutputHeaderPath, std::ios::binary);
|
||||
if (!file.good())
|
||||
{
|
||||
std::cerr << "Open output header failed: " << OutputHeaderPath << std::endl;
|
||||
@@ -342,7 +342,7 @@ namespace
|
||||
file << "#pragma once\n";
|
||||
file << "#include <cstdint>\n";
|
||||
file << "#include \"Image.h\"\n";
|
||||
file << "#include \"SpriteRegion.h\"\n\n";
|
||||
file << "#include \"Sprite.h\"\n\n";
|
||||
file << "namespace TomAtlas\n";
|
||||
file << "{\n";
|
||||
file << "\tstatic const int32_t tom_atlas_width = " << AtlasWidth << ";\n";
|
||||
@@ -355,8 +355,15 @@ namespace
|
||||
const size_t end = std::min(i + 12, atlas_pixels.size());
|
||||
for (size_t j = i; j < end; ++j)
|
||||
{
|
||||
if (j > i)
|
||||
{
|
||||
file << " ";
|
||||
}
|
||||
WritePixel5551(file, atlas_pixels[j]);
|
||||
file << ", ";
|
||||
if (j + 1 < atlas_pixels.size())
|
||||
{
|
||||
file << ",";
|
||||
}
|
||||
}
|
||||
file << "\n";
|
||||
}
|
||||
@@ -369,7 +376,7 @@ namespace
|
||||
for (size_t i = 0; i < regions.size(); ++i)
|
||||
{
|
||||
const AtlasRegion& region = regions[i];
|
||||
file << "\tstatic const RenderData::SpriteRegion "
|
||||
file << "\tstatic const RenderData::Sprite "
|
||||
<< region.source->region_name
|
||||
<< "(&image, "
|
||||
<< region.x << ", "
|
||||
|
||||
Reference in New Issue
Block a user