mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-19 02:05:28 +00:00
refactor(component): group the component files by the client's families
Physics/, Activity/ (activity, scripted activity, shooting gallery, quickbuild, minigame control, racing control base, racing control, gate rush), Vendor/, Character/ (what the client makes with a character, plus ghost, minifig and mission), Sound/ and Property/; the rest stays where it was. File moves only; DLU_COMPONENT_INCLUDE_DIRS gives every target the folders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
15
dGame/dComponents/Sound/RacingSoundTriggerComponent.h
Normal file
15
dGame/dComponents/Sound/RacingSoundTriggerComponent.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef __RACINGSOUNDTRIGGERCOMPONENT__H__
|
||||
#define __RACINGSOUNDTRIGGERCOMPONENT__H__
|
||||
|
||||
#include "SoundTriggerComponent.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
class Entity;
|
||||
|
||||
class RacingSoundTriggerComponent : public SoundTriggerComponent {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::RACING_SOUND_TRIGGER;
|
||||
RacingSoundTriggerComponent(Entity* parent, const int32_t componentID) : SoundTriggerComponent(parent, componentID){};
|
||||
};
|
||||
|
||||
#endif //!__RACINGSOUNDTRIGGERCOMPONENT__H__
|
||||
17
dGame/dComponents/Sound/SoundAmbient2DComponent.h
Normal file
17
dGame/dComponents/Sound/SoundAmbient2DComponent.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SOUNDAMBIENT2DCOMPONENT_H
|
||||
#define SOUNDAMBIENT2DCOMPONENT_H
|
||||
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* A 2D ambient sound the client plays, as the client's LWOSoundAmbient2DComponent; the server sends nothing for it.
|
||||
*/
|
||||
class SoundAmbient2DComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_AMBIENT_2D;
|
||||
|
||||
SoundAmbient2DComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {}
|
||||
};
|
||||
|
||||
#endif // SOUNDAMBIENT2DCOMPONENT_H
|
||||
17
dGame/dComponents/Sound/SoundAmbient3DComponent.h
Normal file
17
dGame/dComponents/Sound/SoundAmbient3DComponent.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SOUNDAMBIENT3DCOMPONENT_H
|
||||
#define SOUNDAMBIENT3DCOMPONENT_H
|
||||
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* A 3D ambient sound the client plays, as the client's LWOSoundAmbient3DComponent; the server sends nothing for it.
|
||||
*/
|
||||
class SoundAmbient3DComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_AMBIENT_3D;
|
||||
|
||||
SoundAmbient3DComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {}
|
||||
};
|
||||
|
||||
#endif // SOUNDAMBIENT3DCOMPONENT_H
|
||||
17
dGame/dComponents/Sound/SoundRepeaterComponent.h
Normal file
17
dGame/dComponents/Sound/SoundRepeaterComponent.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef SOUNDREPEATERCOMPONENT_H
|
||||
#define SOUNDREPEATERCOMPONENT_H
|
||||
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
/**
|
||||
* A repeating sound the client plays (SoundRepeaterComponent row), as the client's LWOSoundRepeaterComponent; the server sends nothing for it.
|
||||
*/
|
||||
class SoundRepeaterComponent final : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_REPEATER;
|
||||
|
||||
SoundRepeaterComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {}
|
||||
};
|
||||
|
||||
#endif // SOUNDREPEATERCOMPONENT_H
|
||||
117
dGame/dComponents/Sound/SoundTriggerComponent.cpp
Normal file
117
dGame/dComponents/Sound/SoundTriggerComponent.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
#include "SoundTriggerComponent.h"
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
|
||||
void MusicCue::Serialize(RakNet::BitStream& outBitStream){
|
||||
outBitStream.Write<uint8_t>(name.size());
|
||||
outBitStream.Write(name.c_str(), name.size());
|
||||
outBitStream.Write(result);
|
||||
outBitStream.Write(boredomTime);
|
||||
}
|
||||
|
||||
void MusicParameter::Serialize(RakNet::BitStream& outBitStream){
|
||||
outBitStream.Write<uint8_t>(name.size());
|
||||
outBitStream.Write(name.c_str(), name.size());
|
||||
outBitStream.Write(value);
|
||||
}
|
||||
|
||||
void GUIDResults::Serialize(RakNet::BitStream& outBitStream){
|
||||
guid.Serialize(outBitStream);
|
||||
outBitStream.Write(result);
|
||||
}
|
||||
|
||||
void MixerProgram::Serialize(RakNet::BitStream& outBitStream){
|
||||
outBitStream.Write<uint8_t>(name.size());
|
||||
outBitStream.Write(name.c_str(), name.size());
|
||||
outBitStream.Write(result);
|
||||
}
|
||||
SoundTriggerComponent::SoundTriggerComponent(Entity* parent, const int32_t componentID) : Component(parent, componentID) {
|
||||
}
|
||||
|
||||
// The level config: music cues and parameters, ambient sounds and mixer programs
|
||||
void SoundTriggerComponent::LoadConfigData() {
|
||||
const auto musicCueName = m_Parent->GetVar<std::string>(u"NDAudioMusicCue_Name");
|
||||
if (!musicCueName.empty()) {
|
||||
auto newCue = MusicCue(musicCueName);
|
||||
const auto musicCueBoredomTime = m_Parent->GetVar<float>(u"NDAudioMusicCue_BoredomTime");
|
||||
if (musicCueBoredomTime) newCue.boredomTime = musicCueBoredomTime;
|
||||
this->m_MusicCues.push_back(newCue);
|
||||
}
|
||||
|
||||
const auto musicParameterName = m_Parent->GetVar<std::string>(u"NDAudioMusicParameter_Name");
|
||||
if (!musicParameterName.empty()) {
|
||||
auto newParams = MusicParameter(musicParameterName);
|
||||
const auto musicParameterValue = m_Parent->GetVar<float>(u"NDAudioMusicParameter_Value");
|
||||
if (musicParameterValue) newParams.value = musicParameterValue;
|
||||
this->m_MusicParameters.push_back(newParams);
|
||||
}
|
||||
|
||||
const auto guidString = m_Parent->GetVar<std::string>(u"NDAudioEventGUID");
|
||||
if (!guidString.empty())
|
||||
this->m_2DAmbientSounds.push_back(GUIDResults(guidString));
|
||||
|
||||
const auto guid2String = m_Parent->GetVar<std::string>(u"NDAudioEventGUID2");
|
||||
if (!guid2String.empty())
|
||||
this->m_3DAmbientSounds.push_back(GUIDResults(guid2String));
|
||||
|
||||
const auto mixerName = m_Parent->GetVar<std::string>(u"NDAudioMixerProgram_Name");
|
||||
if (!mixerName.empty()) this->m_MixerPrograms.push_back(MixerProgram(mixerName));
|
||||
}
|
||||
|
||||
void SoundTriggerComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||
outBitStream.Write(this->m_Dirty || bIsInitialUpdate);
|
||||
if (this->m_Dirty || bIsInitialUpdate) {
|
||||
outBitStream.Write<uint8_t>(this->m_MusicCues.size());
|
||||
for (auto& musicCue : this->m_MusicCues) {
|
||||
musicCue.Serialize(outBitStream);
|
||||
}
|
||||
|
||||
outBitStream.Write<uint8_t>(this->m_MusicParameters.size());
|
||||
for (auto& musicParam : this->m_MusicParameters) {
|
||||
musicParam.Serialize(outBitStream);
|
||||
}
|
||||
|
||||
outBitStream.Write<uint8_t>(this->m_2DAmbientSounds.size());
|
||||
for (auto twoDAmbientSound : this->m_2DAmbientSounds) {
|
||||
twoDAmbientSound.Serialize(outBitStream);
|
||||
}
|
||||
|
||||
outBitStream.Write<uint8_t>(this->m_3DAmbientSounds.size());
|
||||
for (auto threeDAmbientSound : this->m_3DAmbientSounds) {
|
||||
threeDAmbientSound.Serialize(outBitStream);
|
||||
}
|
||||
|
||||
outBitStream.Write<uint8_t>(this->m_MixerPrograms.size());
|
||||
for (auto& mixerProgram : this->m_MixerPrograms) {
|
||||
mixerProgram.Serialize(outBitStream);
|
||||
}
|
||||
|
||||
if (!bIsInitialUpdate) this->m_Dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SoundTriggerComponent::ActivateMusicCue(const std::string& name, float bordemTime) {
|
||||
const auto musicCue = std::find_if(this->m_MusicCues.begin(), this->m_MusicCues.end(), [name](const MusicCue& musicCue) {
|
||||
return musicCue.name == name;
|
||||
}
|
||||
);
|
||||
|
||||
if (musicCue == this->m_MusicCues.end()) {
|
||||
this->m_MusicCues.push_back(MusicCue(name, bordemTime));
|
||||
this->m_Dirty = true;
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
|
||||
void SoundTriggerComponent::DeactivateMusicCue(const std::string& name) {
|
||||
const auto musicCue = std::find_if(this->m_MusicCues.begin(), this->m_MusicCues.end(), [name](const MusicCue& musicCue) {
|
||||
return musicCue.name == name;
|
||||
}
|
||||
);
|
||||
|
||||
if (musicCue != this->m_MusicCues.end()) {
|
||||
this->m_MusicCues.erase(musicCue);
|
||||
this->m_Dirty = true;
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
}
|
||||
79
dGame/dComponents/Sound/SoundTriggerComponent.h
Normal file
79
dGame/dComponents/Sound/SoundTriggerComponent.h
Normal file
@@ -0,0 +1,79 @@
|
||||
#pragma once
|
||||
|
||||
#include "dCommonVars.h"
|
||||
#include "Entity.h"
|
||||
#include "GUID.h"
|
||||
#include "Component.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
|
||||
struct MusicCue {
|
||||
std::string name;
|
||||
uint32_t result;
|
||||
float boredomTime;
|
||||
|
||||
MusicCue(std::string name, float boredomTime = -1.0, uint32_t result = 1){
|
||||
this->name = name;
|
||||
this->result = result;
|
||||
this->boredomTime = boredomTime;
|
||||
};
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream);
|
||||
};
|
||||
|
||||
struct MusicParameter {
|
||||
std::string name;
|
||||
float value;
|
||||
|
||||
MusicParameter(std::string name, float value = 0.0){
|
||||
this->name = name;
|
||||
this->value = value;
|
||||
}
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream);
|
||||
};
|
||||
|
||||
struct GUIDResults{
|
||||
GUID guid;
|
||||
uint32_t result;
|
||||
|
||||
GUIDResults(std::string guidString, uint32_t result = 1){
|
||||
this->guid = GUID(guidString);
|
||||
this->result = result;
|
||||
}
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream);
|
||||
};
|
||||
|
||||
struct MixerProgram {
|
||||
std::string name;
|
||||
uint32_t result;
|
||||
|
||||
MixerProgram(std::string name, uint32_t result = 0){
|
||||
this->name = name;
|
||||
this->result = result;
|
||||
}
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream);
|
||||
};
|
||||
|
||||
|
||||
class SoundTriggerComponent : public Component {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SOUND_TRIGGER;
|
||||
explicit SoundTriggerComponent(Entity* parent, const int32_t componentID);
|
||||
|
||||
void LoadConfigData() override;
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
void ActivateMusicCue(const std::string& name, float bordemTime = -1.0);
|
||||
void DeactivateMusicCue(const std::string& name);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<MusicCue> m_MusicCues;
|
||||
std::vector<MusicParameter> m_MusicParameters;
|
||||
std::vector<GUIDResults> m_2DAmbientSounds;
|
||||
std::vector<GUIDResults> m_3DAmbientSounds;
|
||||
std::vector<MixerProgram> m_MixerPrograms;
|
||||
|
||||
bool m_Dirty = false;
|
||||
};
|
||||
Reference in New Issue
Block a user