Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
DrawSprite.h
1 #pragma once
2 
3 #include <stdint.h>
4 #include <Vector.h>
5 #include <memory>
6 #include <Palette.h>
7 
9 {
10 public:
11  struct Frame
12  {
13  int16_t offsetX;
14  int16_t offsetY;
15  uint16_t width;
16  uint16_t height;
17  const uint8_t* data;
18  };
19 
21  {
22  friend class SpriteRenderer;
23 
24  public:
25  void addSpriteFrame(const Frame& frame);
27 
28  protected:
29  WorldStone::Vector<struct FrameRenderData> framesData;
30  };
31  using SpriteRenderDataHandle = std::weak_ptr<SpriteRenderData>; // This is a poor-man's handle
32  // while waiting for a real
33  // handle system
34 
35  void init(const WorldStone::Palette& palette);
36  int shutdown();
37  void setPalette(const WorldStone::Palette& palette);
38 
39  SpriteRenderDataHandle createSpriteRenderData();
40  void destroySpriteRenderData(SpriteRenderDataHandle);
41 
42  struct Pos2D
43  {
44  float x, y;
45  };
46  struct DrawRequest
47  {
48  Pos2D translation;
49  uint32_t frame;
50  float scale;
51  };
52  void pushDrawRequest(SpriteRenderDataHandle spriteHandle, const DrawRequest& translation);
53 
55  ~SpriteRenderer();
56 
57  bool draw(int screenWidth, int screenHeight);
58 
59 private:
60  void drawFrame(const struct FrameRenderData& renderData);
61  void recycleSpritesData();
62 
63  WorldStone::Vector<std::shared_ptr<SpriteRenderData>> spritesData;
64  WorldStone::Vector<std::pair<std::shared_ptr<SpriteRenderData>, DrawRequest>> spritesToRender;
65 
66  // Should actually be pimpl, but for now data is enough
67  std::unique_ptr<struct SpriteRendererData> data;
68 };
Just a placeholder to use if we ever want to implement our own vector type.
Helper to load a Diablo 2 palette (.pal/.dat format)
Definition: Palette.h:21