Files
itgmania212121/src/ActorMultiVertex.h
T

207 lines
7.1 KiB
C++
Raw Normal View History

2015-02-14 09:54:24 -05:00
/** @brief ActorMultiVertex - An actor with mutiple vertices. Can be used to create shapes that quads can't. */
2014-04-14 21:29:19 -05:00
#include "Actor.h"
#include "CubicSpline.h"
2014-04-14 21:29:19 -05:00
#include "RageDisplay.h"
#include "RageMath.h"
2014-04-14 21:29:19 -05:00
#include "RageTextureID.h"
2023-04-19 23:04:25 +02:00
#include <cstddef>
2023-04-20 19:02:13 +02:00
#include <vector>
2023-04-19 23:04:25 +02:00
2014-04-14 21:29:19 -05:00
enum DrawMode
{
DrawMode_Quads = 0,
DrawMode_QuadStrip,
DrawMode_Fan,
DrawMode_Strip,
DrawMode_Triangles,
DrawMode_LineStrip,
DrawMode_SymmetricQuadStrip,
NUM_DrawMode,
DrawMode_Invalid
};
const RString& DrawModeToString( DrawMode cat );
const RString& DrawModeToLocalizedString( DrawMode cat );
LuaDeclareType( DrawMode );
class RageTexture;
class ActorMultiVertex: public Actor
{
public:
2023-04-19 23:04:25 +02:00
static const std::size_t num_vert_splines= 4;
2014-04-14 21:29:19 -05:00
ActorMultiVertex();
ActorMultiVertex( const ActorMultiVertex &cpy );
virtual ~ActorMultiVertex();
2022-12-23 12:34:02 -07:00
void LoadFromNode( const XNode* Node ) override;
virtual ActorMultiVertex *Copy() const override;
2014-04-14 21:29:19 -05:00
struct AMV_TweenState
{
2015-02-01 17:01:15 -07:00
AMV_TweenState(): _DrawMode(DrawMode_Invalid), FirstToDraw(0),
NumToDraw(-1), line_width(1.0f)
{}
2014-04-14 21:29:19 -05:00
static void MakeWeightedAverage(AMV_TweenState& average_out, const AMV_TweenState& ts1, const AMV_TweenState& ts2, float percent_between);
bool operator==(const AMV_TweenState& other) const;
bool operator!=(const AMV_TweenState& other) const { return !operator==(other); }
void SetDrawState( DrawMode dm, int first, int num );
int GetSafeNumToDraw( DrawMode dm, int num ) const;
std::vector<RageSpriteVertex> vertices;
2023-04-19 23:04:25 +02:00
std::vector<std::size_t> quad_states;
2014-04-14 21:29:19 -05:00
DrawMode _DrawMode;
int FirstToDraw;
int NumToDraw;
// needed for DrawMode_LineStrip
float line_width;
};
AMV_TweenState& AMV_DestTweenState()
{
if(AMV_Tweens.empty())
{ return AMV_current; }
else
{ return AMV_Tweens.back(); }
}
const AMV_TweenState& AMV_DestTweenState() const { return const_cast<ActorMultiVertex*>(this)->AMV_DestTweenState(); }
2022-12-23 12:34:02 -07:00
virtual void EnableAnimation(bool bEnable) override;
virtual void Update(float fDelta) override;
virtual bool EarlyAbortDraw() const override;
virtual void DrawPrimitives() override;
2014-04-14 21:29:19 -05:00
virtual void DrawInternal( const AMV_TweenState *TS );
2023-04-19 23:04:25 +02:00
2022-12-23 12:34:02 -07:00
void SetCurrentTweenStart() override;
void EraseHeadTween() override;
void UpdatePercentThroughTween( float PercentThroughTween ) override;
void BeginTweening( float time, ITween *pInterp ) override;
2014-04-14 21:29:19 -05:00
2022-12-23 12:34:02 -07:00
void StopTweening() override;
void FinishTweening() override;
2023-04-19 23:04:25 +02:00
2014-04-14 21:29:19 -05:00
void SetTexture( RageTexture *Texture );
RageTexture* GetTexture() { return _Texture; };
2014-04-14 21:29:19 -05:00
void LoadFromTexture( RageTextureID ID );
void UnloadTexture();
2023-04-19 23:04:25 +02:00
void SetNumVertices( std::size_t n );
2014-04-14 21:29:19 -05:00
2024-05-18 08:48:56 -07:00
void ResizeVertices(std::vector<RageSpriteVertex>& vertices, int size);
2014-04-14 21:29:19 -05:00
void AddVertex();
void AddVertices( int Add );
void SetEffectMode( EffectMode em) { _EffectMode = em; }
void SetTextureMode( TextureMode tm) { _TextureMode = tm; }
void SetLineWidth( float width) { AMV_DestTweenState().line_width = width; }
void SetDrawState( DrawMode dm, int first, int num ) { AMV_DestTweenState().SetDrawState(dm, first, num); }
DrawMode GetDestDrawMode() const { return AMV_DestTweenState()._DrawMode; }
int GetDestFirstToDraw() const { return AMV_DestTweenState().FirstToDraw; }
int GetDestNumToDraw() const { return AMV_DestTweenState().NumToDraw; }
DrawMode GetCurrDrawMode() const { return AMV_current._DrawMode; }
int GetCurrFirstToDraw() const { return AMV_current.FirstToDraw; }
int GetCurrNumToDraw() const { return AMV_current.NumToDraw; }
2023-04-19 23:04:25 +02:00
std::size_t GetNumVertices() { return AMV_DestTweenState().vertices.size(); }
2014-04-14 21:29:19 -05:00
void SetVertexPos( int index , float x , float y , float z );
void SetVertexColor( int index , RageColor c );
void SetVertexCoords( int index , float TexCoordX , float TexCoordY );
2023-04-19 23:04:25 +02:00
inline void SetVertsFromSplinesInternal(std::size_t num_splines, std::size_t start_vert);
void SetVertsFromSplines();
2023-04-19 23:04:25 +02:00
CubicSplineN* GetSpline(std::size_t i);
2015-02-01 17:01:15 -07:00
struct State
{
RectF rect;
float delay;
};
2022-12-23 12:34:02 -07:00
int GetNumStates() const override { return _states.size(); }
2015-02-01 17:01:15 -07:00
void AddState(const State& new_state) { _states.push_back(new_state); }
2023-04-19 23:04:25 +02:00
void RemoveState(std::size_t i)
2015-02-01 17:01:15 -07:00
{ ASSERT(i < _states.size()); _states.erase(_states.begin()+i); }
2023-04-19 23:04:25 +02:00
std::size_t GetState() { return _cur_state; }
State& GetStateData(std::size_t i)
2015-02-01 17:01:15 -07:00
{ ASSERT(i < _states.size()); return _states[i]; }
2023-04-19 23:04:25 +02:00
void SetStateData(std::size_t i, const State& s)
2015-02-01 17:01:15 -07:00
{ ASSERT(i < _states.size()); _states[i]= s; }
void SetStateProperties(const std::vector<State>& new_states)
2015-02-01 17:01:15 -07:00
{ _states= new_states; SetState(0); }
2022-12-23 12:34:02 -07:00
void SetState(int i) override;
2015-02-01 17:01:15 -07:00
void SetAllStateDelays(float delay);
2022-12-23 12:34:02 -07:00
float GetAnimationLengthSeconds() const override;
void SetSecondsIntoAnimation(float seconds) override;
2015-02-01 17:01:15 -07:00
void UpdateAnimationState(bool force_update= false);
2023-04-19 23:04:25 +02:00
std::size_t GetNumQuadStates() const
2015-02-01 17:01:15 -07:00
{ return AMV_DestTweenState().quad_states.size(); }
2023-04-19 23:04:25 +02:00
void AddQuadState(std::size_t s)
2015-02-01 17:01:15 -07:00
{ AMV_DestTweenState().quad_states.push_back(s); }
2023-04-19 23:04:25 +02:00
void RemoveQuadState(std::size_t i)
2015-02-01 17:01:15 -07:00
{ AMV_DestTweenState().quad_states.erase(AMV_DestTweenState().quad_states.begin()+i); }
2023-04-19 23:04:25 +02:00
std::size_t GetQuadState(std::size_t i)
2015-02-01 17:01:15 -07:00
{ return AMV_DestTweenState().quad_states[i]; }
2023-04-19 23:04:25 +02:00
void SetQuadState(std::size_t i, std::size_t s)
2015-02-01 17:01:15 -07:00
{ AMV_DestTweenState().quad_states[i]= s; }
bool _use_animation_state;
bool _decode_movie;
2015-02-01 17:01:15 -07:00
2022-12-23 12:34:02 -07:00
virtual void PushSelf( lua_State *L ) override;
2014-04-14 21:29:19 -05:00
private:
RageTexture* _Texture;
std::vector<RageSpriteVertex> _Vertices;
std::vector<AMV_TweenState> AMV_Tweens;
2014-04-14 21:29:19 -05:00
AMV_TweenState AMV_current;
AMV_TweenState AMV_start;
// required to handle diffuse and glow
AMV_TweenState *AMV_TempState;
2023-04-19 23:04:25 +02:00
2014-04-14 21:29:19 -05:00
EffectMode _EffectMode;
TextureMode _TextureMode;
// Four splines for controlling vert positions, because quads drawmode
// requires four. -Kyz
std::vector<CubicSplineN> _splines;
2015-02-01 17:01:15 -07:00
bool _skip_next_update;
float _secs_into_state;
2023-04-19 23:04:25 +02:00
std::size_t _cur_state;
std::vector<State> _states;
2014-04-14 21:29:19 -05:00
};
/**
* @file
* @author Matthew Gardner and Eric Reese (c) 2014
* @section LICENSE
* All rights reserved.
2023-04-19 23:04:25 +02:00
*
2014-04-14 21:29:19 -05:00
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
2023-04-19 23:04:25 +02:00
*
2014-04-14 21:29:19 -05:00
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/