@@ -241,6 +241,51 @@ namespace SRL
241241 BottomRight = 0xf
242242 };
243243
244+ /* * @brief Command control type
245+ */
246+ enum class CommandType : uint16_t
247+ {
248+ /* * @brief Standard sprite command
249+ */
250+ StandardSprite = 0x0 ,
251+
252+ /* * @brief Rectangle sprite command
253+ */
254+ RectangleSprite = 0x1 ,
255+
256+ /* * @brief Textured sprite sprite command
257+ */
258+ Texture = 0x2 ,
259+
260+ /* * @brief Filled polygon command
261+ */
262+ Polygon = 0x4 ,
263+
264+ /* * @brief Polyline command
265+ */
266+ PolyLine = 0x5 ,
267+
268+ /* * @brief Simple line segment command
269+ */
270+ LineSegment = 0x6 ,
271+
272+ /* * @brief System clip change command
273+ */
274+ SystemClip = 0x9 ,
275+
276+ /* * @brief User clip change command
277+ */
278+ UserClip = 0x8 ,
279+
280+ /* * @brief Change relative coordinates for VDP1 command table
281+ */
282+ BasePosition = 0xA ,
283+
284+ /* * @brief Draw end command
285+ */
286+ End = 0x80 ,
287+ };
288+
244289 private:
245290
246291 /* * @brief Base address of the gouraud table
@@ -304,31 +349,71 @@ namespace SRL
304349 return Scene2D::Effects.Gouraud >= SRL::Scene2D::GouraudTableBase;
305350 }
306351
307- /* * @brief Generates base shape command
308- * @param type Sprite type
352+ public:
353+
354+ /* *
355+ * @name Sprite/Shape command creation
356+ * @{
357+ */
358+
359+ /* * @brief Generates sprite command based on current effect flags
360+ * @param type Sprite type see SRL::Scene2D::CommandType
309361 * @param color Sprite color
310362 * @return Sprite command
311363 */
312- static constexpr inline SPRITE GetShapeCommand ( uint16_t type, Types::HighColor color)
364+ static constexpr inline SPRITE GetSpriteCommand (Scene2D::CommandType type, Types::HighColor color)
313365 {
314- SPRITE sprite;
315- sprite.COLR = color;
316- sprite.CTRL = type | (Scene2D::IsGouraudEnabled () ? UseGouraud : 0 );
317-
318- sprite.PMOD = 0x0080 |
319- ((CL32KRGB & 7 ) << 3 ) |
320- (Scene2D::IsGouraudEnabled () ? CL_Gouraud : 0 ) |
321- (Scene2D::Effects.ScreenDoors << 8 ) |
322- (Scene2D::Effects.Clipping << 9 ) |
323- (Scene2D::Effects.HalfTransparency ? 0x3 : 0 );
366+ uint16_t gouraudEnabled = Scene2D::IsGouraudEnabled ();
324367
325- sprite.GRDA = (Scene2D::IsGouraudEnabled () ? Scene2D::Effects.Gouraud : 0 );
326- return sprite;
368+ #pragma GCC diagnostic push
369+ #pragma GCC diagnostic ignored "-Wnarrowing"
370+ return {
371+ // Control
372+ (int8_t )type | (gouraudEnabled << 7 ),
373+
374+ // Link address
375+ 0 ,
376+
377+ // Put mode
378+ (uint16_t )(0x0080 |
379+ ((CL32KRGB & 7 ) << 3 ) |
380+ (gouraudEnabled << 2 ) |
381+ (Scene2D::Effects.ScreenDoors << 8 ) |
382+ (Scene2D::Effects.Clipping << 9 ) |
383+ (Scene2D::Effects.HalfTransparency ? 0x3 : 0 )),
384+
385+ // Sprite Color
386+ color,
387+
388+ // Texture source
389+ 0 ,
390+
391+ // Texture size
392+ 0 ,
393+
394+ // X,Y coordinates as 16bit integer, repeated 4 times
395+ 0 ,
396+ 0 ,
397+ 0 ,
398+ 0 ,
399+ 0 ,
400+ 0 ,
401+ 0 ,
402+ 0 ,
403+
404+ // Gouraud
405+ Scene2D::Effects.Gouraud ,
406+
407+ // Dummy variable
408+ 0
409+ };
410+ #pragma GCC diagnostic pop
327411 }
328412
329- /* * @brief Generates sprite attributes struct
413+ /* * @brief Generates sprite attributes struct based on current effect flags
330414 * @param texture Texture identifier
331415 * @param texturePalette Palette override
416+ * @param zoomPoint Sprite zoom (origin) point
332417 * @return Sprite attributes
333418 */
334419 static constexpr inline SPR_ATTR GetSpriteAttribute (
@@ -394,13 +479,47 @@ namespace SRL
394479 (zoomPoint << 8 ));
395480 #pragma GCC diagnostic pop
396481 }
397- public:
482+
483+ /* * @} */
398484
399485 /* *
400486 * @name Draw functions
401487 * @{
402488 */
403489
490+ /* * @brief Draw sprite by using a custom command
491+ * @param command Custom command
492+ * @param depth Depth sort value
493+ * @return True on success
494+ */
495+ static bool Draw (SPRITE* command, const SRL::Math::Types::Fxp& depth)
496+ {
497+ return slSetSprite (command, depth.RawValue ());
498+ }
499+
500+ /* * @brief Draw sprite by using custom attributes
501+ * @param attributes Custom sprite attributes
502+ * @param arguments Sprite attribute arguments
503+ * @return True on success
504+ */
505+ static bool Draw (SPR_ATTR* attributes, const SRL::Math::Types::Fxp* arguments)
506+ {
507+ // We cannot use slDispSprite, as that seems to be bugged and is drawing images 1px wider than it should
508+ return slDispSpriteHV ((FIXED*)arguments, attributes, 0 ) != 0 ;
509+ }
510+
511+ /* * @brief Draw sprite by using custom attributes and 4 points
512+ * @param attributes Custom sprite attributes
513+ * @param points Corners of the sprite in screen coordinates
514+ * @param depth Depth sort value
515+ * @return True on success
516+ */
517+ static bool Draw (SPR_ATTR* attributes, const SRL::Math::Types::Vector2D points[4 ], const SRL::Math::Types::Fxp depth)
518+ {
519+ // We cannot use slDispSprite, as that seems to be bugged and is drawing images 1px wider than it should
520+ return slDispSprite4P ((FIXED*)points, depth.RawValue (), attributes) != 0 ;
521+ }
522+
404523 /* * @brief Draw sprite from 4 points
405524 * @param texture Sprite texture
406525 * @param texturePalette Sprite texture color palette override
@@ -609,7 +728,7 @@ namespace SRL
609728 */
610729 static bool DrawLine (const SRL::Math::Types::Vector2D& start,const SRL::Math::Types::Vector2D& end, const Types::HighColor& color, const SRL::Math::Types::Fxp sort)
611730 {
612- SPRITE line = Scene2D::GetShapeCommand (FUNC_Line , color);
731+ SPRITE line = Scene2D::GetSpriteCommand (Scene2D::CommandType::LineSegment , color);
613732 line.XA = start.X .As <int16_t >();
614733 line.YA = start.Y .As <int16_t >();
615734 line.XB = end.X .As <int16_t >();
@@ -625,7 +744,7 @@ namespace SRL
625744 */
626745 static bool DrawPolygon (SRL::Math::Types::Vector2D points[4 ], const bool fill, const Types::HighColor& color, const SRL::Math::Types::Fxp sort)
627746 {
628- SPRITE polygon = Scene2D::GetShapeCommand (fill ? FUNC_Polygon : FUNC_PolyLine , color);
747+ SPRITE polygon = Scene2D::GetSpriteCommand (fill ? Scene2D::CommandType::Polygon : Scene2D::CommandType::PolyLine , color);
629748 polygon.XA = points[0 ].X .As <int16_t >();
630749 polygon.YA = points[0 ].Y .As <int16_t >();
631750 polygon.XB = points[1 ].X .As <int16_t >();
0 commit comments