Skip to content

Commit

Permalink
PE: Added Wicked Particle System (LUA only for now).
Browse files Browse the repository at this point in the history
  • Loading branch information
plemsoft committed Jan 17, 2025
1 parent 4270c30 commit 04479c5
Show file tree
Hide file tree
Showing 6 changed files with 590 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

//#define FASTBULLETPHYSICS

#ifdef WINVER
#undef WINVER
#endif
//PE: We need the latest dpi functions.
#define WINVER 0x0605
#include "Windows.h"
#include "WinUser.h"

#define _USING_V110_SDK71_
#include "stdafx.h"
#include "DarkLUA.h"
Expand Down Expand Up @@ -45,6 +53,13 @@ extern StoryboardStruct Storyboard;
#include "optick.h"
#endif

#include "..\..\..\..\Guru-WickedMAX\wickedcalls.h"
#include "WickedEngine.h"
using namespace std;
using namespace wiGraphics;
using namespace wiScene;
using namespace wiECS;

// Prototypes
extern void DrawSpritesFirst(void);
extern void DrawSpritesLast(void);
Expand Down Expand Up @@ -9736,6 +9751,172 @@ int EffectSetLifespan(lua_State* L)
return 0;
}

#ifdef WICKEDPARTICLESYSTEM
std::vector<uint32_t> vWickedEmitterEffects;
void CleanUpEmitterEffects(void)
{
Scene& scene = wiScene::GetScene();

std::vector<uint32_t> vEntityDelete;
for (int i = 0; i < vWickedEmitterEffects.size(); i++)
{
uint32_t root = vWickedEmitterEffects[i];
for (int a = 0; a < scene.emitters.GetCount(); a++)
{
Entity emitter = scene.emitters.GetEntity(a);
HierarchyComponent* hier = scene.hierarchy.GetComponent(emitter);
if (hier)
{
if (hier->parentID == root)
{
vEntityDelete.push_back(emitter);
}
}
}
vEntityDelete.push_back(root);
}

for (int i = 0; i < vEntityDelete.size(); i++)
{
scene.Entity_Remove(vEntityDelete[i]);
}
vEntityDelete.clear();
vWickedEmitterEffects.clear();
}

//PE: WParticleEffectPosition("FileName") - Return EffectID
int WParticleEffectLoad(lua_State* L)
{
lua = L;
int n = lua_gettop(L);
if (n < 1) return 0;

Scene& scene = wiScene::GetScene();

char pFileName[MAX_PATH];
strcpy(pFileName, lua_tostring(L, 1));

uint32_t root = 0;
uint32_t count_before = scene.emitters.GetCount();

cstr pOldDir = GetDir();

char path[MAX_PATH];
strcpy(path, pFileName);
GG_GetRealPath(path, 0);

WickedCall_LoadWiScene(path, false, NULL, NULL);
uint32_t count_after = scene.emitters.GetCount();
if (count_before != count_after)
{
Entity emitter = scene.emitters.GetEntity(scene.emitters.GetCount() - 1);
if (scene.emitters.GetCount() > 0)
{
Entity emitter = scene.emitters.GetEntity(0);
HierarchyComponent* hier = scene.hierarchy.GetComponent(emitter);
if (hier)
{
root = hier->parentID;
}
}
wiEmittedParticle* ec = scene.emitters.GetComponent(emitter);
if (ec)
{
ec->Restart();
ec->SetVisible(true);
}
}
if (root != 0)
vWickedEmitterEffects.push_back(root);
lua_pushnumber(L, root);
return 1;

}
//PE: WParticleEffectPosition(EffectID,x,y,z)
int WParticleEffectPosition(lua_State* L)
{
lua = L;
int n = lua_gettop(L);
if (n < 4) return 0;

Entity root = lua_tonumber(L, 1);
float fX = lua_tonumber(L, 2);
float fY = lua_tonumber(L, 3);
float fZ = lua_tonumber(L, 4);

Scene& scene = wiScene::GetScene();
TransformComponent* root_tranform = scene.transforms.GetComponent(root);
if (root_tranform)
{
root_tranform->ClearTransform();
root_tranform->Translate(XMFLOAT3(fX, fY, fZ));
root_tranform->UpdateTransform();
}

//for (int i = 0; i < scene.emitters.GetCount(); i++)
//{
// Entity emitter = scene.emitters.GetEntity(i);
// HierarchyComponent* hier = scene.hierarchy.GetComponent(emitter);
// if (hier)
// {
// if (hier->parentID == root)
// {
// }
// }
//}

return 0;
}
int WParticleEffectVisible(lua_State* L)
{
lua = L;
int n = lua_gettop(L);
if (n < 2) return 0;

Entity root = lua_tonumber(L, 1);
bool bVisible = lua_tonumber(L, 2);

Scene& scene = wiScene::GetScene();

for (int i = 0; i < scene.emitters.GetCount(); i++)
{
Entity emitter = scene.emitters.GetEntity(i);
HierarchyComponent* hier = scene.hierarchy.GetComponent(emitter);
if (hier)
{
if (hier->parentID == root)
{
wiEmittedParticle* ec = scene.emitters.GetComponent(emitter);
if (ec)
{
ec->SetVisible(bVisible);
}
}
}
}

return 0;
}

//WParticleEffectAction(EffectID,Action) - Action = 1 Burst all. 2 = Pause. - 3 = Resume. - 4 = Restart
int WParticleEffectAction(lua_State* L)
{
lua = L;
int n = lua_gettop(L);
if (n < 2) return 0;
Entity root = lua_tonumber(L, 1);
int iAction = lua_tonumber(L, 2);
WickedCall_PerformEmitterAction(iAction, root);
return 0;
}

// rotate
// Stop
// copy lua code from app.
// add emitter with all settings.
#endif


// Misc Commands

int GetBulletHit(lua_State* L)
Expand Down Expand Up @@ -12801,6 +12982,15 @@ void addFunctions()
lua_register(lua, "EffectSetColor", EffectSetColor);
lua_register(lua, "EffectSetLifespan", EffectSetLifespan);

//PE: Wicked particle system.
#ifdef WICKEDPARTICLESYSTEM
lua_register(lua, "WParticleEffectLoad", WParticleEffectLoad);
lua_register(lua, "WParticleEffectPosition", WParticleEffectPosition);
lua_register(lua, "WParticleEffectVisible", WParticleEffectVisible);
lua_register(lua, "WParticleEffectAction", WParticleEffectAction);

#endif

lua_register(lua, "GetBulletHit", GetBulletHit);
lua_register(lua, "SetFlashLight" , SetFlashLight );
lua_register(lua, "SetAttachmentVisible" , SetAttachmentVisible );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DARKLUA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>GGREDUCED;WIN32;NDEBUG;_WINDOWS;_USRDLL;DARKLUA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level1</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>lua;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\Include\;$(ProjectDir)..\..\..\..\Dark Wicked Shared\Include\;$(ProjectDir)..\..\..\..\GameGuru\Include\;$(ProjectDir)..\..\..\..\SDK\RecastContrib;$(ProjectDir)..\..\..\..\SDK\RecastContrib\fastlz;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DebugUtils/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\Detour/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DetourCrowd/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DetourTileCache/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\Recast/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\;$(ProjectDir)..\..\..\..\SDK\RecastContrib\SDL\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../../../../../WICKEDREPO/WickedEngine;lua;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\Include\;$(ProjectDir)..\..\..\..\Dark Wicked Shared\Include\;$(ProjectDir)..\..\..\..\GameGuru\Include\;$(ProjectDir)..\..\..\..\SDK\RecastContrib;$(ProjectDir)..\..\..\..\SDK\RecastContrib\fastlz;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DebugUtils/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\Detour/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DetourCrowd/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DetourTileCache/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\Recast/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\;$(ProjectDir)..\..\..\..\SDK\RecastContrib\SDL\include</AdditionalIncludeDirectories>
<WholeProgramOptimization>false</WholeProgramOptimization>
<DisableSpecificWarnings>4005;4995;4723</DisableSpecificWarnings>
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
Expand Down Expand Up @@ -133,14 +133,14 @@
<ClCompile>
<Optimization>Disabled</Optimization>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DARKLUA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>GGREDUCED;WIN32;NDEBUG;_WINDOWS;_USRDLL;DARKLUA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level1</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>lua;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\Include\;$(ProjectDir)..\..\..\..\Dark Wicked Shared\Include\;$(ProjectDir)..\..\..\..\GameGuru\Include\;$(ProjectDir)..\..\..\..\SDK\RecastContrib;$(ProjectDir)..\..\..\..\SDK\RecastContrib\fastlz;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DebugUtils/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\Detour/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DetourCrowd/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DetourTileCache/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\Recast/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\;$(ProjectDir)..\..\..\..\SDK\RecastContrib\SDL\include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../../../../../WICKEDREPO/WickedEngine;lua;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\Include\;$(ProjectDir)..\..\..\..\Dark Wicked Shared\Include\;$(ProjectDir)..\..\..\..\GameGuru\Include\;$(ProjectDir)..\..\..\..\SDK\RecastContrib;$(ProjectDir)..\..\..\..\SDK\RecastContrib\fastlz;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DebugUtils/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\Detour/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DetourCrowd/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\DetourTileCache/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\Recast/Include;$(ProjectDir)..\..\..\..\Guru-WickedMAX\GGRecastDetour\;$(ProjectDir)..\..\..\..\SDK\RecastContrib\SDL\include</AdditionalIncludeDirectories>
<WholeProgramOptimization>false</WholeProgramOptimization>
<DisableSpecificWarnings>4005;4995;4723</DisableSpecificWarnings>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
Expand Down
2 changes: 2 additions & 0 deletions GameGuru Core/GameGuru/Include/preprocessor-moreflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
#define NEWPROJSYSWORKINPROGRESS
#define DETECTANDUSENEWPARTICLEDECALS

#define WICKEDPARTICLESYSTEM

#else
// Flags to compile the Classic version of GameGuru
#define FPSEXCHANGE
Expand Down
4 changes: 4 additions & 0 deletions GameGuru Core/Guru-WickedMAX/master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,10 @@ void MasterRenderer::Update(float dt)
}
wiProfiler::EndRange(range3);

#ifdef WICKEDPARTICLESYSTEM
WickedCall_UpdateEmitters();
#endif

// now just prepared IMGUI, but actual render called from Wicked hook
auto range2 = wiProfiler::BeginRangeCPU("Update - Render");
GuruLoopRender();
Expand Down
Loading

0 comments on commit 04479c5

Please sign in to comment.