Skip to content

Commit 181449a

Browse files
committed
[Tools] Adds ParticleEditor implementation.
Adds dll implementing the ParticleEditor API used by the game. Uses same struct layout as ZH so should work correctly.
1 parent b3f11ab commit 181449a

32 files changed

+7300
-4
lines changed

cmake/modules/VersionResource.rc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include <winres.h>
1414
#endif
1515

16+
#ifdef INCLUDE_WX_MANIFEST
17+
#include <wx/msw/wx.rc>
18+
#endif
19+
1620
#ifdef PRODUCT_ICON
1721
IDI_ICON1 ICON PRODUCT_ICON
1822
#endif

src/game/client/system/particlesystem/particleinfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ParticleInfo : public SnapShot
2929
{
3030
friend class ParticleSystem;
3131
friend class Particle;
32+
friend class ParticleSystemsDialog;
3233

3334
enum
3435
{

src/game/client/system/particlesystem/particlesysinfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
class ParticleSystemInfo : public SnapShot
3030
{
3131
friend class ParticleSystemManager;
32+
friend class ParticleSystemsDialog;
3233

33-
protected:
34+
public:
3435
enum
3536
{
3637
KEYFRAME_COUNT = 8,
@@ -44,6 +45,7 @@ class ParticleSystemInfo : public SnapShot
4445
EMISSION_VELOCITY_HEMISPHERICAL,
4546
EMISSION_VELOCITY_CYLINDRICAL,
4647
EMISSION_VELOCITY_OUTWARD,
48+
EMISSION_VELOCITY_COUNT,
4749
};
4850

4951
union EmissionVelocityUnion
@@ -86,6 +88,7 @@ class ParticleSystemInfo : public SnapShot
8688
EMISSION_VOLUME_BOX,
8789
EMISSION_VOLUME_SPHERE,
8890
EMISSION_VOLUME_CYLINDER,
91+
EMISSION_VOLUME_COUNT,
8992
};
9093

9194
union EmissionVolumeUnion
@@ -130,6 +133,7 @@ class ParticleSystemInfo : public SnapShot
130133
PARTICLE_SHADER_ALPHA,
131134
PARTICLE_SHADER_ALPHA_TEST,
132135
PARTICLE_SHADER_MULTIPLY,
136+
PARTICLE_SHADER_COUNT,
133137
};
134138

135139
enum ParticleType : int32_t
@@ -140,6 +144,7 @@ class ParticleSystemInfo : public SnapShot
140144
PARTICLE_TYPE_STREAK,
141145
PARTICLE_TYPE_VOLUME_PARTICLE,
142146
PARTICLE_TYPE_SMUDGE,
147+
PARTICLE_TYPE_COUNT,
143148
};
144149

145150
struct RandomKeyframe

src/game/client/system/particlesystem/particlesystemplate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class ParticleSystem;
2525
class ParticleSystemTemplate : public MemoryPoolObject, public ParticleSystemInfo
2626
{
2727
friend class ParticleSystem;
28+
29+
// These friend classes are for the particle system editor plugin.
30+
friend class ParticleSystemsDialog;
31+
2832
IMPLEMENT_NAMED_POOL(ParticleSystemTemplate, ParticleSystemTemplatePool);
2933

3034
protected:

src/game/common/randomvalue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class GameClientRandomVariable
6767
operator float() const { return Get_Value(); }
6868

6969
void Set_Range(float min, float max, DistributionType type);
70+
void Set_Min(float min) { m_low = min; }
71+
void Set_Max(float max) { m_high = max; }
7072
float Get_Value() const;
7173
float Get_Min() const { return m_low; }
7274
float Get_Max() const { return m_high; }

src/tools/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
if(wxWidgets_FOUND)
33
include(TargetExports)
44
add_subdirectory(debugwindow)
5+
add_subdirectory(particleed)
56
endif()

src/tools/debugwindow/dbgwinapp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ DbgWinApp::DbgWinApp() : m_frame(nullptr)
4444

4545
bool DbgWinApp::OnInit()
4646
{
47-
4847
wxXmlResource *res = wxXmlResource::Get();
4948
res->AddHandler(new wxUnknownWidgetXmlHandler);
5049
// res->AddHandler(new wxBitmapXmlHandler);

src/tools/debugwindow/dbgwinframe.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ void DbgWinFrame::On_Exit(wxCloseEvent &event)
6363

6464
void DbgWinFrame::On_Thumb(wxScrollWinEvent &event)
6565
{
66-
printf("Handling scroll thumb event.\n");
6766
if (!m_blockVariableUpdate) {
6867
m_blockVariableUpdate = true;
6968
}
7069
}
7170

7271
void DbgWinFrame::On_Thumb_Release(wxScrollWinEvent &event)
7372
{
74-
printf("Handling scroll thumb release event.\n");
7573
m_blockVariableUpdate = false;
7674
}
7775

src/tools/particleed/CMakeLists.txt

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
add_library(particleeditor SHARED)
2+
target_link_libraries(particleeditor PRIVATE ${wxWidgets_LIBRARIES} base captnlog)
3+
4+
if(USE_GAMEMATH)
5+
target_link_libraries(particleeditor PRIVATE gamemath_static_lib)
6+
target_compile_definitions(particleeditor PRIVATE -DBUILD_WITH_GAMEMATH)
7+
endif()
8+
9+
target_include_directories(particleeditor PRIVATE
10+
${CMAKE_CURRENT_BINARY_DIR}
11+
${wxWidgets_INCLUDE_DIRS}
12+
${CMAKE_SOURCE_DIR}/src/game
13+
${CMAKE_SOURCE_DIR}/src/game/client
14+
${CMAKE_SOURCE_DIR}/src/game/client/gui
15+
${CMAKE_SOURCE_DIR}/src/game/client/input
16+
${CMAKE_SOURCE_DIR}/src/game/client/shadow
17+
${CMAKE_SOURCE_DIR}/src/game/client/shader
18+
${CMAKE_SOURCE_DIR}/src/game/client/system
19+
${CMAKE_SOURCE_DIR}/src/game/client/system/particlesystem
20+
${CMAKE_SOURCE_DIR}/src/game/client/videoplayer
21+
${CMAKE_SOURCE_DIR}/src/game/common
22+
${CMAKE_SOURCE_DIR}/src/game/common/audio
23+
${CMAKE_SOURCE_DIR}/src/game/common/compression
24+
${CMAKE_SOURCE_DIR}/src/game/common/ini
25+
${CMAKE_SOURCE_DIR}/src/game/common/modules
26+
${CMAKE_SOURCE_DIR}/src/game/common/rts
27+
${CMAKE_SOURCE_DIR}/src/game/common/system
28+
${CMAKE_SOURCE_DIR}/src/game/common/thing
29+
${CMAKE_SOURCE_DIR}/src/game/logic/ai
30+
${CMAKE_SOURCE_DIR}/src/game/logic/map
31+
${CMAKE_SOURCE_DIR}/src/game/logic/object
32+
${CMAKE_SOURCE_DIR}/src/game/logic/scriptengine
33+
${CMAKE_SOURCE_DIR}/src/game/logic/system
34+
${CMAKE_SOURCE_DIR}/src/game/client/system/particlesystem
35+
${CMAKE_SOURCE_DIR}/src/w3d/lib
36+
${CMAKE_SOURCE_DIR}/src/w3d/math
37+
${CMAKE_SOURCE_DIR}/src/w3d/renderer
38+
${CMAKE_SOURCE_DIR}/src/w3d/saveload
39+
)
40+
target_compile_options(particleeditor PRIVATE ${wxWidgets_CXX_FLAGS})
41+
target_compile_definitions(particleeditor PRIVATE ${wxWidgets_DEFINITIONS})
42+
43+
if (NOT STANDALONE)
44+
target_compile_definitions(particleeditor PRIVATE -DGAME_DLL)
45+
endif()
46+
47+
if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows")
48+
target_compile_definitions(particleeditor PRIVATE
49+
-DWIN32_LEAN_AND_MEAN
50+
-D_CRT_SECURE_NO_DEPRECATE
51+
-D_CRT_NONSTDC_NO_DEPRECATE
52+
-D_WINSOCK_DEPRECATED_NO_WARNINGS
53+
-DwxUSE_RC_MANIFEST
54+
)
55+
56+
57+
include(ProductVersion)
58+
59+
generate_product_version(PARTICLEED_RC
60+
NAME "Particle Editor Plugin DLL"
61+
BUNDLE "Thyme"
62+
VERSION_MAJOR 1
63+
VERSION_MINOR 0
64+
COMPANY_NAME "Assembly Armada"
65+
COMPANY_COPYRIGHT "Built from code licensed under GPLv2 or later."
66+
ORIGINAL_FILENAME "ParticleEditor.dll"
67+
RCFILE_PREFIX "ParticleEditor"
68+
)
69+
endif()
70+
71+
if(NOT wxWidgets_wxrc_EXECUTABLE)
72+
message(FATAL_ERROR "wxrc resource compiler was not found, please set wxWidgets_wxrc_EXECUTABLE manually.")
73+
endif()
74+
75+
# Generate cpp/h files to embed xml resources in the binary.
76+
add_custom_command(
77+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/wxpartedui.cpp" "${CMAKE_CURRENT_BINARY_DIR}/wxpartedui.h"
78+
COMMAND ${wxWidgets_wxrc_EXECUTABLE} --cpp-code --extra-cpp-code --output=${CMAKE_CURRENT_BINARY_DIR}/wxpartedui.cpp ${CMAKE_CURRENT_SOURCE_DIR}/ui/partedui.xrc
79+
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/ui/partedui.xrc"
80+
)
81+
82+
target_sources(particleeditor PRIVATE
83+
dllmain.cpp
84+
coloralpha.cpp
85+
coloralpha.h
86+
emissionpanels.cpp
87+
emissionpanels.h
88+
emitswitch.cpp
89+
emitswitch.h
90+
moreparams.cpp
91+
moreparams.h
92+
partedapp.cpp
93+
partedapp.h
94+
partedframe.cpp
95+
partedframe.h
96+
particleeditor.cpp
97+
particleeditor.h
98+
particlepanels.cpp
99+
particlepanels.h
100+
velocitypanels.cpp
101+
velocitypanels.h
102+
${CMAKE_CURRENT_BINARY_DIR}/wxpartedui.cpp
103+
${CMAKE_CURRENT_BINARY_DIR}/wxpartedui.h
104+
${PARTICLEED_RC}
105+
)
106+
107+
if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows")
108+
target_sources(particleeditor PRIVATE particleeditor_win32.cpp)
109+
else()
110+
target_sources(particleeditor PRIVATE particleeditor_posix.cpp)
111+
endif()
112+
113+
set_target_properties(particleeditor PROPERTIES OUTPUT_NAME ParticleEditor PREFIX "")
114+
115+
target_exports(particleeditor SYMBOLS
116+
HasRequestedKillAllSystems
117+
HasRequestedReload
118+
AppendParticleSystem
119+
AppendThingTemplate
120+
CreateParticleSystemDialog
121+
DestroyParticleSystemDialog
122+
GetNewParticleCap
123+
GetSelectedParticleAsciiStringParm
124+
GetSelectedParticleSystemName
125+
HasUpdatedSelectedParticleSystem
126+
NextParticleEditorBehavior
127+
RemoveAllParticleSystems
128+
RemoveAllThingTemplates
129+
ShouldBusyWait
130+
ShouldReloadTextures
131+
ShouldUpdateParticleCap
132+
ShouldWriteINI
133+
UpdateCurrentNumParticles
134+
UpdateCurrentParticleCap
135+
UpdateCurrentParticleSystem
136+
UpdateParticleAsciiStringParm
137+
UpdateSystemUseParameters
138+
)

src/tools/particleed/coloralpha.cpp

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#include "coloralpha.h"
2+
#include "partedapp.h"
3+
#include "partedframe.h"
4+
#include <wx/valnum.h>
5+
#include <wx/valtext.h>
6+
7+
ColorAndAlphaDialog::ColorAndAlphaDialog(wxWindow *parent) : ColorAlphaBase(parent)
8+
{
9+
// Convenience array to allow iteration in other class methods.
10+
m_controls[0].color_picker = m_colKeyCheck1;
11+
m_controls[0].color_frame = m_colKeyFrame1;
12+
m_controls[0].alpha_min = m_alphaKeyMin1;
13+
m_controls[0].alpha_max = m_alphaKeyMax1;
14+
m_controls[0].alpha_frame = m_alphaKeyFrame1;
15+
m_controls[1].color_picker = m_colKeyCheck2;
16+
m_controls[1].color_frame = m_colKeyFrame2;
17+
m_controls[1].alpha_min = m_alphaKeyMin2;
18+
m_controls[1].alpha_max = m_alphaKeyMax2;
19+
m_controls[1].alpha_frame = m_alphaKeyFrame2;
20+
m_controls[2].color_picker = m_colKeyCheck3;
21+
m_controls[2].color_frame = m_colKeyFrame3;
22+
m_controls[2].alpha_min = m_alphaKeyMin3;
23+
m_controls[2].alpha_max = m_alphaKeyMax3;
24+
m_controls[2].alpha_frame = m_alphaKeyFrame3;
25+
m_controls[3].color_picker = m_colKeyCheck4;
26+
m_controls[3].color_frame = m_colKeyFrame4;
27+
m_controls[3].alpha_min = m_alphaKeyMin4;
28+
m_controls[3].alpha_max = m_alphaKeyMax4;
29+
m_controls[3].alpha_frame = m_alphaKeyFrame4;
30+
m_controls[4].color_picker = m_colKeyCheck5;
31+
m_controls[4].color_frame = m_colKeyFrame5;
32+
m_controls[4].alpha_min = m_alphaKeyMin5;
33+
m_controls[4].alpha_max = m_alphaKeyMax5;
34+
m_controls[4].alpha_frame = m_alphaKeyFrame5;
35+
m_controls[5].color_picker = m_colKeyCheck6;
36+
m_controls[5].color_frame = m_colKeyFrame6;
37+
m_controls[5].alpha_min = m_alphaKeyMin6;
38+
m_controls[5].alpha_max = m_alphaKeyMax6;
39+
m_controls[5].alpha_frame = m_alphaKeyFrame6;
40+
m_controls[6].color_picker = m_colKeyCheck7;
41+
m_controls[6].color_frame = m_colKeyFrame7;
42+
m_controls[6].alpha_min = m_alphaKeyMin7;
43+
m_controls[6].alpha_max = m_alphaKeyMax7;
44+
m_controls[6].alpha_frame = m_alphaKeyFrame7;
45+
m_controls[7].color_picker = m_colKeyCheck8;
46+
m_controls[7].color_frame = m_colKeyFrame8;
47+
m_controls[7].alpha_min = m_alphaKeyMin8;
48+
m_controls[7].alpha_max = m_alphaKeyMax8;
49+
m_controls[7].alpha_frame = m_alphaKeyFrame8;
50+
51+
Bind(wxEVT_COLOURPICKER_CHANGED, &ColorAndAlphaDialog::On_Button, this, XRCID("m_colKeyCheck1"));
52+
Bind(wxEVT_COLOURPICKER_CHANGED, &ColorAndAlphaDialog::On_Button, this, XRCID("m_colKeyCheck2"));
53+
Bind(wxEVT_COLOURPICKER_CHANGED, &ColorAndAlphaDialog::On_Button, this, XRCID("m_colKeyCheck3"));
54+
Bind(wxEVT_COLOURPICKER_CHANGED, &ColorAndAlphaDialog::On_Button, this, XRCID("m_colKeyCheck4"));
55+
Bind(wxEVT_COLOURPICKER_CHANGED, &ColorAndAlphaDialog::On_Button, this, XRCID("m_colKeyCheck5"));
56+
Bind(wxEVT_COLOURPICKER_CHANGED, &ColorAndAlphaDialog::On_Button, this, XRCID("m_colKeyCheck6"));
57+
Bind(wxEVT_COLOURPICKER_CHANGED, &ColorAndAlphaDialog::On_Button, this, XRCID("m_colKeyCheck7"));
58+
Bind(wxEVT_COLOURPICKER_CHANGED, &ColorAndAlphaDialog::On_Button, this, XRCID("m_colKeyCheck8"));
59+
}
60+
61+
void ColorAndAlphaDialog::On_Button(wxCommandEvent &event)
62+
{
63+
// TODO call update.
64+
}
65+
66+
void ColorAndAlphaDialog::Init_Entries()
67+
{
68+
wxTextValidator validator(wxFILTER_NUMERIC);
69+
wxFloatingPointValidator<float> fpval(2, nullptr, wxNUM_VAL_ZERO_AS_BLANK);
70+
71+
for (int i = 0; i < 8; ++i) {
72+
m_controls[i].color_frame->SetValidator(validator);
73+
m_controls[i].alpha_frame->SetValidator(validator);
74+
m_controls[i].alpha_min->SetValidator(fpval);
75+
m_controls[i].alpha_max->SetValidator(fpval);
76+
}
77+
}
78+
79+
void ColorAndAlphaDialog::Update(bool update_dialogs)
80+
{
81+
static_assert(ParticleSystemInfo::KEYFRAME_COUNT <= 8, "Control array size is too small and needs adjusting.");
82+
ParticleSystemsDialog *wxframe = wxGetApp().Frame();
83+
84+
if (wxframe == nullptr) {
85+
return;
86+
}
87+
88+
if (update_dialogs) {
89+
for (int i = 0; i < ParticleSystemInfo::KEYFRAME_COUNT; ++i) {
90+
char buff[128];
91+
92+
// Handle Color
93+
RGBColorKeyframe color_key;
94+
wxframe->Get_Color_Key_Frame(i, color_key);
95+
std::snprintf(buff, sizeof(buff), "%" PRIu32, color_key.frame);
96+
m_controls[i].color_picker->SetColour(wxColour(color_key.color.red, color_key.color.green, color_key.color.blue));
97+
m_controls[i].color_frame->SetValue(buff);
98+
99+
// Handle Alpha
100+
ParticleSystemInfo::RandomKeyframe alpha_key;
101+
wxframe->Get_Alpha_Key_Frame(i, alpha_key);
102+
std::snprintf(buff, sizeof(buff), "%" PRIu32, alpha_key.frame);
103+
m_controls[i].alpha_frame->SetValue(buff);
104+
std::snprintf(buff, sizeof(buff), "%.2f", alpha_key.var.Get_Min());
105+
m_controls[i].alpha_min->SetValue(buff);
106+
std::snprintf(buff, sizeof(buff), "%.2f", alpha_key.var.Get_Max());
107+
m_controls[i].alpha_max->SetValue(buff);
108+
}
109+
} else {
110+
for (int i = 0; i < ParticleSystemInfo::KEYFRAME_COUNT; ++i) {
111+
// Handle Color
112+
RGBColorKeyframe color_key;
113+
wxColour color = m_controls[i].color_picker->GetColour();
114+
color_key.color.red = color.Red() / 255.0f;
115+
color_key.color.green = color.Green() / 255.0f;
116+
color_key.color.blue = color.Blue() / 255.0f;
117+
color_key.frame = std::atoi(m_controls[i].color_frame->GetValue());
118+
wxframe->Set_Color_Key_Frame(i, color_key);
119+
120+
// Handle Alpha
121+
ParticleSystemInfo::RandomKeyframe alpha_key;
122+
wxframe->Get_Alpha_Key_Frame(i, alpha_key);
123+
alpha_key.frame = std::atoi(m_controls[i].alpha_frame->GetValue());
124+
alpha_key.var.Set_Min(std::atof(m_controls[i].alpha_min->GetValue()));
125+
alpha_key.var.Set_Max(std::atof(m_controls[i].alpha_max->GetValue()));
126+
wxframe->Set_Alpha_Key_Frame(i, alpha_key);
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)