mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-19 17:59:18 +02:00
basic events code refactor, support for multiple event targets
This commit is contained in:
237
Event.h
237
Event.h
@@ -14,6 +14,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "names.h"
|
||||
#include "evlaunch.h"
|
||||
|
||||
//#define EU07_USE_LEGACY_EVENTS
|
||||
|
||||
#ifdef EU07_USE_LEGACY_EVENTS
|
||||
enum TEventType {
|
||||
tp_Unknown,
|
||||
tp_Sound,
|
||||
@@ -204,5 +207,239 @@ private:
|
||||
basic_table<TEventLauncher> m_launchers;
|
||||
eventlauncher_sequence m_launcherqueue;
|
||||
};
|
||||
#else
|
||||
enum TEventType {
|
||||
tp_Unknown,
|
||||
tp_Sound,
|
||||
tp_Animation,
|
||||
tp_Lights,
|
||||
tp_UpdateValues,
|
||||
tp_GetValues,
|
||||
tp_PutValues,
|
||||
tp_Switch,
|
||||
tp_TrackVel,
|
||||
tp_Multiple,
|
||||
tp_AddValues,
|
||||
tp_CopyValues,
|
||||
tp_WhoIs,
|
||||
tp_LogValues,
|
||||
tp_Visible,
|
||||
tp_Voltage,
|
||||
tp_Message,
|
||||
tp_Friction
|
||||
};
|
||||
|
||||
const int update_memstring = 0x0000001; // zmodyfikować tekst (UpdateValues)
|
||||
const int update_memval1 = 0x0000002; // zmodyfikować pierwszą wartosć
|
||||
const int update_memval2 = 0x0000004; // zmodyfikować drugą wartosć
|
||||
const int update_memadd = 0x0000008; // dodać do poprzedniej zawartości
|
||||
const int update_load = 0x0000010; // odczytać ładunek
|
||||
const int conditional_memstring = 0x0000100; // porównanie tekstu
|
||||
const int conditional_memval1 = 0x0000200; // porównanie pierwszej wartości liczbowej
|
||||
const int conditional_memval2 = 0x0000400; // porównanie drugiej wartości
|
||||
const int conditional_trackoccupied = 0x1000000; // jeśli tor zajęty
|
||||
const int conditional_trackfree = 0x2000000; // jeśli tor wolny
|
||||
const int conditional_propability = 0x4000000; // zależnie od generatora lizcb losowych
|
||||
const int conditional_memcompare = 0x8000000; // porównanie zawartości
|
||||
|
||||
// zdarzenie
|
||||
class TEvent {
|
||||
|
||||
friend event_manager;
|
||||
|
||||
public:
|
||||
// types
|
||||
// wrapper for binding between editor-supplied name, event, and execution conditional flag
|
||||
using conditional_event = std::tuple<std::string, TEvent *, bool>;
|
||||
using basic_node = std::tuple<std::string, scene::basic_node *>;
|
||||
using basic_sound = std::tuple<std::string, sound_source *>;
|
||||
// constructors
|
||||
TEvent();
|
||||
~TEvent();
|
||||
// metody
|
||||
void Load(cParser *parser, Math3D::vector3 const &org);
|
||||
// sends basic content of the class in legacy (text) format to provided stream
|
||||
template <class TableType_>
|
||||
void
|
||||
init_targets( TableType_ &Repository, std::string const &Targettype, bool const Logerrors = true );
|
||||
void
|
||||
init_conditions();
|
||||
void
|
||||
export_as_text( std::ostream &Output ) const;
|
||||
static void AddToQuery( TEvent *Event, TEvent *&Start );
|
||||
std::string CommandGet() const;
|
||||
TCommandType Command() const;
|
||||
double ValueGet(int n) const;
|
||||
glm::dvec3 PositionGet() const;
|
||||
bool StopCommand() const;
|
||||
void StopCommandSent();
|
||||
void Append(TEvent *e);
|
||||
void
|
||||
group( scene::group_handle Group );
|
||||
scene::group_handle
|
||||
group() const;
|
||||
// members
|
||||
std::string asName;
|
||||
TEventType Type = tp_Unknown;
|
||||
TEvent *evNext = nullptr; // następny w kolejce
|
||||
bool m_ignored{ false }; // replacement for tp_ignored
|
||||
bool bEnabled = false; // false gdy ma nie być dodawany do kolejki (skanowanie sygnałów)
|
||||
int iQueued = 0; // ile razy dodany do kolejki
|
||||
TDynamicObject const *Activator = nullptr;
|
||||
double fStartTime = 0.0;
|
||||
double fDelay = 0.0;
|
||||
double fRandomDelay = 0.0; // zakres dodatkowego opóźnienia // standardowo nie będzie dodatkowego losowego opóźnienia
|
||||
TEvent *evJoined = nullptr; // kolejny event z tą samą nazwą - od wersji 378
|
||||
std::vector<basic_node> m_targets; // targets of operation performed when this event is executed
|
||||
std::vector<conditional_event> m_children; // events which are placed in the query when this event is executed
|
||||
std::vector<float> m_lights; // for tp_lights
|
||||
bool m_visible { true }; // for tp_visible
|
||||
double m_velocity { 0.0 }; // for tp_trackvel
|
||||
std::vector<basic_sound> m_sounds; // for tp_sound
|
||||
int m_soundmode{ 0 };
|
||||
int m_soundradiochannel{ 0 };
|
||||
int m_animationtype{ 0 }; // for tp_animation
|
||||
std::array<double, 4> m_animationparams{ 0.0 };
|
||||
std::string m_animationsubmodel;
|
||||
std::vector<TAnimContainer *> m_animationcontainers;
|
||||
std::string m_animationfilename;
|
||||
std::size_t m_animationfilesize{ 0 };
|
||||
char *m_animationfiledata{ nullptr };
|
||||
int m_switchstate{ 0 }; // for tp_switch
|
||||
float m_switchmoverate{ -1.f };
|
||||
float m_switchmovedelay{ -1.f };
|
||||
float m_friction { -1.f }; // for tp_friction
|
||||
float m_voltage{ -1.f }; // for tp_voltage
|
||||
|
||||
private:
|
||||
// types
|
||||
struct update_data {
|
||||
unsigned int flags { 0 };
|
||||
std::string data_text;
|
||||
double data_value_1 { 0.0 };
|
||||
double data_value_2 { 0.0 };
|
||||
basic_node data_source { "", nullptr };
|
||||
glm::dvec3 location { 0.0 };
|
||||
TCommandType command_type { TCommandType::cm_Unknown };
|
||||
|
||||
TMemCell const * data_cell() const;
|
||||
TMemCell * data_cell();
|
||||
};
|
||||
struct condition_data {
|
||||
unsigned int flags { 0 };
|
||||
float probability { 0.0 }; // used by conditional_probability
|
||||
double match_value_1 { 0.0 }; // used by conditional_memcompare
|
||||
double match_value_2 { 0.0 }; // used by conditional_memcompare
|
||||
std::string match_text; // used by conditional_memcompare
|
||||
std::vector<TTrack *> tracks; // used by conditional_track
|
||||
bool has_else { false };
|
||||
|
||||
void load( cParser &Input );
|
||||
};
|
||||
// methods
|
||||
void load_targets( std::string const &Input );
|
||||
std::string type_to_string() const;
|
||||
// members
|
||||
scene::group_handle m_group { null_handle }; // group this event belongs to, if any
|
||||
update_data m_update;
|
||||
condition_data m_condition;
|
||||
};
|
||||
|
||||
inline
|
||||
void
|
||||
TEvent::group( scene::group_handle Group ) {
|
||||
m_group = Group;
|
||||
}
|
||||
|
||||
inline
|
||||
scene::group_handle
|
||||
TEvent::group() const {
|
||||
return m_group;
|
||||
}
|
||||
|
||||
template <class TableType_>
|
||||
void
|
||||
TEvent::init_targets( TableType_ &Repository, std::string const &Targettype, bool const Logerrors ) {
|
||||
|
||||
for( auto &target : m_targets ) {
|
||||
std::get<scene::basic_node *>( target ) = Repository.find( std::get<std::string>( target ) );
|
||||
if( std::get<scene::basic_node *>( target ) == nullptr ) {
|
||||
m_ignored = true; // deaktywacja
|
||||
if( Logerrors )
|
||||
ErrorLog( "Bad event: " + type_to_string() + " event \"" + asName + "\" cannot find " + Targettype +" \"" + std::get<std::string>( target ) + "\"" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class event_manager {
|
||||
|
||||
public:
|
||||
// constructors
|
||||
event_manager() = default;
|
||||
// destructor
|
||||
~event_manager();
|
||||
// methods
|
||||
// adds specified event launcher to the list of global launchers
|
||||
void
|
||||
queue( TEventLauncher *Launcher );
|
||||
// legacy method, updates event queues
|
||||
void
|
||||
update();
|
||||
// adds provided event to the collection. returns: true on success
|
||||
// TBD, TODO: return handle to the event
|
||||
bool
|
||||
insert( TEvent *Event );
|
||||
bool
|
||||
insert( TEventLauncher *Launcher ) {
|
||||
return m_launchers.insert( Launcher ); }
|
||||
// returns first event in the queue
|
||||
TEvent *
|
||||
begin() {
|
||||
return QueryRootEvent; }
|
||||
// legacy method, returns pointer to specified event, or null
|
||||
TEvent *
|
||||
FindEvent( std::string const &Name );
|
||||
// legacy method, inserts specified event in the event query
|
||||
bool
|
||||
AddToQuery( TEvent *Event, TDynamicObject const *Owner );
|
||||
// legacy method, executes queued events
|
||||
bool
|
||||
CheckQuery();
|
||||
// legacy method, initializes events after deserialization from scenario file
|
||||
void
|
||||
InitEvents();
|
||||
// legacy method, initializes event launchers after deserialization from scenario file
|
||||
void
|
||||
InitLaunchers();
|
||||
// sends basic content of the class in legacy (text) format to provided stream
|
||||
void
|
||||
export_as_text( std::ostream &Output ) const;
|
||||
|
||||
private:
|
||||
// types
|
||||
using event_sequence = std::deque<TEvent *>;
|
||||
using event_map = std::unordered_map<std::string, std::size_t>;
|
||||
using eventlauncher_sequence = std::vector<TEventLauncher *>;
|
||||
|
||||
// methods
|
||||
// legacy method, verifies condition for specified event
|
||||
bool
|
||||
EventConditon( TEvent *Event );
|
||||
|
||||
// members
|
||||
event_sequence m_events;
|
||||
/*
|
||||
// NOTE: disabled until event class refactoring
|
||||
event_sequence m_eventqueue;
|
||||
*/
|
||||
// legacy version of the above
|
||||
TEvent *QueryRootEvent { nullptr };
|
||||
TEvent *m_workevent { nullptr };
|
||||
event_map m_eventmap;
|
||||
basic_table<TEventLauncher> m_launchers;
|
||||
eventlauncher_sequence m_launcherqueue;
|
||||
};
|
||||
#endif
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
13
MemCell.cpp
13
MemCell.cpp
@@ -112,13 +112,13 @@ bool TMemCell::Load(cParser *parser)
|
||||
return true;
|
||||
}
|
||||
|
||||
void TMemCell::PutCommand( TController *Mech, glm::dvec3 const *Loc )
|
||||
void TMemCell::PutCommand( TController *Mech, glm::dvec3 const *Loc ) const
|
||||
{ // wysłanie zawartości komórki do AI
|
||||
if (Mech)
|
||||
Mech->PutCommand(szText, fValue1, fValue2, Loc);
|
||||
}
|
||||
|
||||
bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) {
|
||||
bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) const {
|
||||
// porównanie zawartości komórki pamięci z podanymi wartościami
|
||||
if( TestFlag( CheckMask, conditional_memstring ) ) {
|
||||
// porównać teksty
|
||||
@@ -194,7 +194,7 @@ TMemCell::export_as_text_( std::ostream &Output ) const {
|
||||
<< fValue1 << ' '
|
||||
<< fValue2 << ' '
|
||||
// associated track
|
||||
<< ( asTrackName.empty() ? "none" : asTrackName ) << ' '
|
||||
<< ( Track ? Track->name() : asTrackName.empty() ? "none" : asTrackName ) << ' '
|
||||
// footer
|
||||
<< "endmemcell"
|
||||
<< "\n";
|
||||
@@ -210,6 +210,13 @@ memory_table::InitCells() {
|
||||
for( auto *cell : m_items ) {
|
||||
// Ra: eventy komórek pamięci, wykonywane po wysłaniu komendy do zatrzymanego pojazdu
|
||||
cell->AssignEvents( simulation::Events.FindEvent( cell->name() + ":sent" ) );
|
||||
// bind specified path with the memory cell
|
||||
if( false == cell->asTrackName.empty() ) {
|
||||
cell->Track = simulation::Paths.find( cell->asTrackName );
|
||||
if( cell->Track == nullptr ) {
|
||||
ErrorLog( "Bad memcell: track \"" + cell->asTrackName + "\" referenced in memcell \"" + cell->name() + "\" doesn't exist" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
14
MemCell.h
14
MemCell.h
@@ -16,19 +16,17 @@ http://mozilla.org/MPL/2.0/.
|
||||
class TMemCell : public scene::basic_node {
|
||||
|
||||
public:
|
||||
std::string asTrackName; // McZapkie-100302 - zeby nazwe toru na ktory jest Putcommand wysylane pamietac
|
||||
bool is_exportable { true }; // export helper; autogenerated cells don't need to be exported
|
||||
|
||||
// constructors
|
||||
explicit TMemCell( scene::node_data const &Nodedata );
|
||||
|
||||
// methods
|
||||
void
|
||||
UpdateValues( std::string const &szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask );
|
||||
bool
|
||||
Load(cParser *parser);
|
||||
void
|
||||
PutCommand( TController *Mech, glm::dvec3 const *Loc );
|
||||
PutCommand( TController *Mech, glm::dvec3 const *Loc ) const;
|
||||
bool
|
||||
Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask );
|
||||
Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) const;
|
||||
std::string const &
|
||||
Text() const {
|
||||
return szText; }
|
||||
@@ -48,6 +46,10 @@ public:
|
||||
TCommandType CommandCheck();
|
||||
bool IsVelocity() const;
|
||||
void AssignEvents(TEvent *e);
|
||||
// members
|
||||
std::string asTrackName; // McZapkie-100302 - zeby nazwe toru na ktory jest Putcommand wysylane pamietac
|
||||
TTrack *Track { nullptr }; // resolved binding with the specified track
|
||||
bool is_exportable { true }; // export helper; autogenerated cells don't need to be exported
|
||||
|
||||
private:
|
||||
// methods
|
||||
|
||||
Reference in New Issue
Block a user