Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MagicFlare refactors #292

Open
wants to merge 122 commits into
base: master
Choose a base branch
from
Open
Changes from 10 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
dcf58db
MagicFlare: Encapsulate magic flare array in a container
bsxf-47 Sep 10, 2023
d3fc2c8
MagicFlare: Turn MagicFlare into its own class
bsxf-47 Sep 10, 2023
4b6d53a
MagicFlare: Extract member function
bsxf-47 Sep 10, 2023
5c8e212
MagicFlare: Extract member variable
bsxf-47 Sep 10, 2023
579512e
MagicFlare: Move declarations and definitions
bsxf-47 Sep 10, 2023
0eccf1a
MagicFlare: Extract member function
bsxf-47 Sep 10, 2023
8f7adc5
MagicFlares: Extract member function
bsxf-47 Sep 10, 2023
ee87ccc
MagicFlare: Extract member variable
bsxf-47 Sep 10, 2023
24798dc
MagicFlare: Extract member function
bsxf-47 Sep 10, 2023
c9e2852
MagicFlare: Extract member function
bsxf-47 Sep 10, 2023
0311a2f
MagicFlare: Extract function
bsxf-47 Sep 10, 2023
454a82b
MagicFlare: Extract member variable
bsxf-47 Sep 10, 2023
3bcb375
MagicFlare: Extract member variable
bsxf-47 Sep 10, 2023
977ae05
MagicFlare: Extract member function
bsxf-47 Sep 10, 2023
8c0b908
MagicFlare: Rename member variable
bsxf-47 Sep 10, 2023
ec30783
MagicFlare: Initialize member variables
bsxf-47 Sep 10, 2023
eadeab4
MagicFlare: Extract member function
bsxf-47 Sep 10, 2023
22e0192
MagicFlare: Extract member function
bsxf-47 Sep 12, 2023
bbb410c
MagicFlare: Start index at zero
bsxf-47 Sep 12, 2023
7e14259
MagicFlare: Use correct array size
bsxf-47 Sep 12, 2023
c6811ad
MagicFlare: Rename member variable
bsxf-47 Sep 12, 2023
e5c8e10
MagicFlare: Rename variable
bsxf-47 Sep 13, 2023
9c62384
MagicFlare: Rewrite to switch
bsxf-47 Sep 13, 2023
b512d7b
MagicFlare: Extract member function
bsxf-47 Sep 13, 2023
4f834b9
MagicFlare: Remove nested for loop
bsxf-47 Sep 13, 2023
07baa88
MagicFlare: Rename member variable
bsxf-47 Sep 13, 2023
a4758b8
MagicFlare: Change type to bool
bsxf-47 Sep 13, 2023
e7a647e
MagicFlare: Rename variable
bsxf-47 Sep 14, 2023
3914787
MagicFlare: Include texture loading in init()
bsxf-47 Sep 14, 2023
7694002
MagicFlare: Extract member function
bsxf-47 Sep 14, 2023
6cfdba4
MagicFlare: Rename member variable
bsxf-47 Sep 14, 2023
5e51e8a
MagicFlare: Rename member variable
bsxf-47 Sep 14, 2023
34159b2
MagicFlare: Don't use object
bsxf-47 Sep 14, 2023
0f04799
MagicFlare: Extract member function
bsxf-47 Sep 14, 2023
6cf2952
MagicFlare: Rename variable
bsxf-47 Sep 14, 2023
c4a508a
MagicFlare: Extract member function
bsxf-47 Sep 14, 2023
b02d768
MagicFlare: Rename parameter
bsxf-47 Sep 17, 2023
3201f23
MagicFlare: Rename parameter
bsxf-47 Sep 17, 2023
4c5a97f
MagicFlare: Rename variable
bsxf-47 Sep 17, 2023
da458ca
MagicFlare: Rename variable
bsxf-47 Sep 17, 2023
c3ae0e9
MagicFlare: Rename variable
bsxf-47 Sep 17, 2023
011bdcd
MagicFlare: Rename variable
bsxf-47 Sep 17, 2023
c78e461
MagicFlare: Rename variable
bsxf-47 Sep 17, 2023
bb105e2
MagicFlare: Change parameter type
bsxf-47 Sep 17, 2023
e8e8e2b
MagicFlare: Rename parameter
bsxf-47 Sep 17, 2023
b52752d
MagicFlare: Rewrite decimal as fraction
bsxf-47 Sep 17, 2023
f198476
MagicFlare: Rewrite decimal as fraction
bsxf-47 Sep 17, 2023
9e6e1d6
MagicFlare: Rename member function
bsxf-47 Sep 17, 2023
7770695
MagicFlare: Rename function
bsxf-47 Sep 17, 2023
df81970
MagicFlare: Rename member function
bsxf-47 Sep 17, 2023
9e101f0
MagicFlare: Use member variable
bsxf-47 Sep 19, 2023
ad1e260
MagicFlare: Use member variable
bsxf-47 Sep 19, 2023
a185213
MagicFlare: Use member variable
bsxf-47 Sep 19, 2023
21bfa24
MagicFlare: Use member variable
bsxf-47 Sep 19, 2023
2746bf9
MagicFlare: Use member variable
bsxf-47 Sep 19, 2023
42050a9
MagicFlare: Use member variable
bsxf-47 Sep 19, 2023
157a967
MagicFlare: Use member variable directly
bsxf-47 Sep 19, 2023
d47a8c3
MagicFlare: Use member variable
bsxf-47 Sep 19, 2023
da41d18
MagicFlare: Rename member variable
bsxf-47 Sep 19, 2023
f5c315c
MagicFlare: Extract member function
bsxf-47 Sep 19, 2023
b000752
MagicFlare: Rename member variable
bsxf-47 Sep 20, 2023
2d05c94
MagicFlare: Rename member variable
bsxf-47 Sep 20, 2023
1acded0
MagicFlare: Use member variable instead of local one
bsxf-47 Sep 21, 2023
932fcb1
MagicFlare: Extract member function
bsxf-47 Sep 21, 2023
6c32b89
MagicFlare: Rename member variable
bsxf-47 Sep 21, 2023
f1fb9b6
MagicFlare: Use member variable instead of a local one
bsxf-47 Sep 21, 2023
6ff6653
MagicFlare: Move code to member function
bsxf-47 Sep 21, 2023
555a648
MagicFlare: Invert logic
bsxf-47 Sep 21, 2023
3ffaae0
MagicFlare: Remove unnecessary check
bsxf-47 Sep 21, 2023
fddccb8
MagicFlare: Change type to bool
bsxf-47 Sep 21, 2023
ea34562
MagicFlare: Rename member variable
bsxf-47 Sep 21, 2023
854b5e4
MagicFlare: Rename class
bsxf-47 Sep 23, 2023
ff6edf6
MagicFlare: Define a container class for flares
bsxf-47 Sep 24, 2023
f899d92
MagicFlare: Move overloaded operator to container class
bsxf-47 Sep 24, 2023
32a2fe5
MagicFlare: Use container class
bsxf-47 Sep 24, 2023
ffafb01
MagicFlare: Use member function
bsxf-47 Sep 24, 2023
f11c8d7
MagicFlare: Move definition
bsxf-47 Sep 24, 2023
db16861
MagicFlare: Move member function to container class
bsxf-47 Sep 24, 2023
e402a12
MagicFlare: Move member function to container class
bsxf-47 Sep 24, 2023
7353ad4
MagicFlare: Use member function
bsxf-47 Sep 24, 2023
a7a5de2
MagicFlare: Make member function private
bsxf-47 Sep 24, 2023
ebfad35
MagicFlare: Use for loop range
bsxf-47 Sep 24, 2023
9b0775d
MagicFlare: Use for loop range
bsxf-47 Sep 24, 2023
ba5511d
MagicFlare: Use for loop range
bsxf-47 Sep 24, 2023
3d94c9c
MagicFlare: Use for loop range
bsxf-47 Sep 24, 2023
923f05c
MagicFlare: Use for loop range
bsxf-47 Sep 24, 2023
d866cac
MagicFlare: Remove obsolete operator
bsxf-47 Sep 24, 2023
77a643a
MagicFlare: Remove unused member variable
bsxf-47 Sep 24, 2023
2366070
MagicFlare: Remove now unused member variable
bsxf-47 Sep 26, 2023
49fb792
MagicFlare: Make member variable private
bsxf-47 Sep 26, 2023
3aeb707
MagicFlare: Remove dead code
bsxf-47 Sep 28, 2023
69245b0
MagicFlare: Clear IO information on clear()
bsxf-47 Sep 30, 2023
2d24b2a
MagicFlare: Extract member function
bsxf-47 Sep 30, 2023
3c6fd75
MegicFlare: Extract member function
bsxf-47 Sep 30, 2023
ab47139
MagicFlare: Clear type on clear()
bsxf-47 Oct 1, 2023
27a28e9
MagicFlare: Use member function
bsxf-47 Oct 1, 2023
401ae2c
MagicFlare: Move texture container logic
bsxf-47 Oct 1, 2023
9228319
MagicFlare: Move definition
bsxf-47 Oct 1, 2023
009c0a5
MagicFlare: Move definition
bsxf-47 Oct 1, 2023
d12e1e8
MagicFlare: Remove unneeded parameter
bsxf-47 Oct 1, 2023
c3d1389
MagicFlare: Rename member function
bsxf-47 Oct 1, 2023
95a7d7a
MagicFlare: Rename member variable
bsxf-47 Oct 1, 2023
33ab1e2
MagicFlare: Use member variable
bsxf-47 Oct 1, 2023
ea54c2f
MagicFlare: Remove extraneous parameter
bsxf-47 Oct 1, 2023
13c30a8
MagicFlare: Remove extraneous parameter
bsxf-47 Oct 1, 2023
8adccd3
MagicFlare: Use member variable
bsxf-47 Oct 1, 2023
ed26163
MagicFlare: Remove extraneous parameter
bsxf-47 Oct 1, 2023
4625215
MagicFlare: Use wrapper function
bsxf-47 Oct 1, 2023
c6202e2
MagicFlare: Use wrapper function
bsxf-47 Oct 1, 2023
12c5ed3
MagicFlare: Use wrapper function
bsxf-47 Oct 1, 2023
43c9f6e
MagicFlare: Use Vec2f
bsxf-47 Oct 1, 2023
1712bf2
MagicFlare: Use Vec2f
bsxf-47 Oct 1, 2023
c13c337
MagicFlare: Use local variables
bsxf-47 Oct 1, 2023
b90e79b
MagicFlare: Use local variables
bsxf-47 Oct 1, 2023
0284750
MagicFlare: Remove redundant check
bsxf-47 Oct 1, 2023
70f175e
MagicFlare: Rewrite function to remove duplicate code
bsxf-47 Oct 3, 2023
bc53268
MagicFlare: Remove helper function
bsxf-47 Oct 3, 2023
96ef76f
MagicFlare: Extract member function
bsxf-47 Oct 3, 2023
903c15b
MagicFlare: Pass positions as const references
bsxf-47 Oct 3, 2023
de938f5
MagicFlare: Remove redundant member variable
bsxf-47 Oct 3, 2023
80d6021
MagicFlare: Fix code style
bsxf-47 Oct 5, 2023
8811a16
MagicFlare: Mark constructor as explicit
bsxf-47 Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 158 additions & 114 deletions src/graphics/particle/MagicFlare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@
#include "graphics/data/TextureContainer.h"
#include "math/RandomVector.h"

struct MagicFlare {
struct FLARETC {
TextureContainer* lumignon;
TextureContainer* lumignon2;
TextureContainer* plasm;
TextureContainer* shine[11];
};

static FLARETC g_magicFlareTextures;

class MagicFlare {
public:
unsigned char exist;
char type;
short flags;
Expand All @@ -56,105 +66,32 @@ struct MagicFlare {
};

static const size_t g_magicFlaresMax = 500;
static MagicFlare g_magicFlares[g_magicFlaresMax];
static long g_magicFlaresCount = 0;
static short g_magicFlareCurrentColor = 0;

struct FLARETC
{
TextureContainer * lumignon;
TextureContainer * lumignon2;
TextureContainer * plasm;
TextureContainer * shine[11];
class MagicFlareContainer {
public:
MagicFlare& operator[](size_t element);
void removeFlare(MagicFlare& flare);
void addFlare(const Vec2f& pos, float sm, short typ, Entity* io, bool bookDraw);
long flaggedCount();
void removeFlareEntityPtr(const Entity* entity);
void init();
void removeAll();

short shinum = 1;
private:
MagicFlare m_flares[g_magicFlaresMax];
};

static FLARETC g_magicFlareTextures;

void MagicFlareLoadTextures() {

TextureContainer::TCFlags flags = TextureContainer::NoColorKey;

g_magicFlareTextures.lumignon = TextureContainer::LoadUI("graph/particles/lumignon", flags);
g_magicFlareTextures.lumignon2 = TextureContainer::LoadUI("graph/particles/lumignon2", flags);
g_magicFlareTextures.plasm = TextureContainer::LoadUI("graph/particles/plasm", flags);

std::ostringstream oss;
for(size_t i = 1; i < 10; i++) {
oss.str(std::string());
oss << "graph/particles/shine" << i;
g_magicFlareTextures.shine[i] = TextureContainer::LoadUI(oss.str(), flags);
}

}

static short shinum = 1;

void MagicFlareReleaseEntity(const Entity * entity) {
for(size_t i = 0; i < g_magicFlaresMax; i++) {
if(g_magicFlares[i].exist && g_magicFlares[i].io == entity) {
g_magicFlares[i].io = nullptr;
}
}
}
static MagicFlareContainer g_magicFlares;

long MagicFlareCountNonFlagged() {

if(!g_magicFlaresCount)
return 0;
MagicFlare& MagicFlareContainer::operator[](size_t element) {

long count = 0;
for(size_t i = 0; i < g_magicFlaresMax; i++) {
if(g_magicFlares[i].exist && g_magicFlares[i].flags == 0) {
count++;
}
}

return count;
return m_flares[element];
}

void ARX_MAGICAL_FLARES_FirstInit() {
g_magicFlaresCount = 0;
for(size_t i = 0; i < g_magicFlaresMax; i++) {
g_magicFlares[i].exist = 0;
}
}

static void removeFlare(MagicFlare & flare) {

if(flare.io && ValidIOAddress(flare.io)) {
flare.io->flarecount--;
}

lightHandleDestroy(flare.dynlight);

flare.tolive = 0;
flare.exist = 0;
g_magicFlaresCount--;

}

void ARX_MAGICAL_FLARES_KillAll() {

for(size_t i = 0; i < g_magicFlaresMax; i++) {
MagicFlare & flare = g_magicFlares[i];
if(flare.exist) {
removeFlare(flare);
}
}

g_magicFlaresCount = 0;
}

static short g_magicFlareCurrentColor = 0;

void MagicFlareChangeColor() {
g_magicFlareCurrentColor++;

if(g_magicFlareCurrentColor > 2)
g_magicFlareCurrentColor = 0;
}

void AddFlare(const Vec2f & pos, float sm, short typ, Entity * io, bool bookDraw) {

void MagicFlareContainer::addFlare(const Vec2f& pos, float sm, short typ, Entity* io, bool bookDraw) {
size_t oldest = 0;
size_t i;
for(i = 0; i < g_magicFlaresMax; i++) {
Expand All @@ -166,16 +103,16 @@ void AddFlare(const Vec2f & pos, float sm, short typ, Entity * io, bool bookDraw
}
}
if(i >= g_magicFlaresMax) {
removeFlare(g_magicFlares[oldest]);
g_magicFlares.removeFlare(g_magicFlares[oldest]);
i = oldest;
}

MagicFlare & flare = g_magicFlares[i];
MagicFlare& flare = g_magicFlares[i];
flare.exist = 1;
g_magicFlaresCount++;

flare.bDrawBitmap = bookDraw;

flare.io = io;
if(io) {
flare.flags = 1;
Expand All @@ -202,21 +139,24 @@ void AddFlare(const Vec2f & pos, float sm, short typ, Entity * io, bool bookDraw
}

switch(g_magicFlareCurrentColor) {
case 0: {
case 0:
{
flare.rgb = Color3f(0.4f, 0.f, 0.4f) + Color3f(2.f / 3, 2.f / 3, 2.f / 3) * randomColor3f();
break;
}
case 1: {
case 1:
{
flare.rgb = Color3f(0.5f, 0.5f, 0.f) + Color3f(0.625f, 0.625f, 0.55f) * randomColor3f();
break;
}
case 2: {
case 2:
{
flare.rgb = Color3f(0.4f, 0.f, 0.f) + Color3f(2.f / 3, 0.55f, 0.55f) * randomColor3f();
break;
}
default: arx_unreachable();
}

if(typ == -1) {
float zz = eeMousePressed1() ? 0.29f : ((sm > 0.5f) ? Random::getf() : 1.f);
if(zz < 0.2f) {
Expand All @@ -237,20 +177,20 @@ void AddFlare(const Vec2f & pos, float sm, short typ, Entity * io, bool bookDraw
flare.size = Random::getf(64.f, 102.f) * sm;
flare.tolive = Random::get(3400000us, 4400000us);
}
flare.dynlight = { };

flare.dynlight = {};

for(unsigned int kk = 0; kk < 3; kk++) {

if(Random::getf() < 0.5f) {
continue;
}
PARTICLE_DEF * pd = createParticle(true);

PARTICLE_DEF* pd = createParticle(true);
if(!pd) {
break;
}

if(!bookDraw) {
pd->m_flags = FADE_IN_AND_OUT | ROTATING | DISSIPATING;
if(!io) {
Expand All @@ -259,7 +199,7 @@ void AddFlare(const Vec2f & pos, float sm, short typ, Entity * io, bool bookDraw
} else {
pd->m_flags = FADE_IN_AND_OUT | PARTICLE_2D;
}

pd->ov = flare.p + arx::randomVec(-5.f, 5.f);
pd->move = Vec3f(0.f, 5.f, 0.f);
pd->sizeDelta = -2.f;
Expand All @@ -273,9 +213,113 @@ void AddFlare(const Vec2f & pos, float sm, short typ, Entity * io, bool bookDraw
}
pd->rgb = flare.rgb * (2.f / 3);
pd->m_rotation = 1.2f;


}
}

void MagicFlareContainer::removeFlare(MagicFlare& flare) {

if(flare.io && ValidIOAddress(flare.io)) {
flare.io->flarecount--;
}

lightHandleDestroy(flare.dynlight);

flare.tolive = 0;
flare.exist = 0;
g_magicFlaresCount--;

}

long MagicFlareContainer::flaggedCount() {
if(!g_magicFlaresCount)
return 0;

long count = 0;
for(size_t i = 0; i < g_magicFlaresMax; i++) {
if(g_magicFlares[i].exist && g_magicFlares[i].flags == 0) {
count++;
}
}

return count;
}

void MagicFlareContainer::removeFlareEntityPtr(const Entity* entity) {

for(size_t i = 0; i < g_magicFlaresMax; i++) {
if(g_magicFlares[i].exist && g_magicFlares[i].io == entity) {
g_magicFlares[i].io = nullptr;
}
}
}

void MagicFlareContainer::init() {
g_magicFlaresCount = 0;
for(size_t i = 0; i < g_magicFlaresMax; i++) {
g_magicFlares[i].exist = 0;
}
}

void MagicFlareContainer::removeAll() {

for(size_t i = 0; i < g_magicFlaresMax; i++) {
MagicFlare& flare = g_magicFlares[i];
Copy link
Member

@dscharrer dscharrer Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be MagicFlare & flare

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 80d6021.

if(flare.exist) {
g_magicFlares.removeFlare(flare);
}
}

g_magicFlaresCount = 0;
}

void MagicFlareLoadTextures() {

TextureContainer::TCFlags flags = TextureContainer::NoColorKey;

g_magicFlareTextures.lumignon = TextureContainer::LoadUI("graph/particles/lumignon", flags);
g_magicFlareTextures.lumignon2 = TextureContainer::LoadUI("graph/particles/lumignon2", flags);
g_magicFlareTextures.plasm = TextureContainer::LoadUI("graph/particles/plasm", flags);

std::ostringstream oss;
for(size_t i = 1; i < 10; i++) {
oss.str(std::string());
oss << "graph/particles/shine" << i;
g_magicFlareTextures.shine[i] = TextureContainer::LoadUI(oss.str(), flags);
}

}

void MagicFlareReleaseEntity(const Entity * entity) {

g_magicFlares.removeFlareEntityPtr(entity);
}

long MagicFlareCountNonFlagged() {

return g_magicFlares.flaggedCount();
}

void ARX_MAGICAL_FLARES_FirstInit() {

g_magicFlares.init();
}

void ARX_MAGICAL_FLARES_KillAll() {

g_magicFlares.removeAll();
}

void MagicFlareChangeColor() {
g_magicFlareCurrentColor++;

if(g_magicFlareCurrentColor > 2)
g_magicFlareCurrentColor = 0;
}

void AddFlare(const Vec2f & pos, float sm, short typ, Entity * io, bool bookDraw) {

g_magicFlares.addFlare(pos, sm, typ, io, bookDraw);
}

//! Helper for FlareLine
Expand Down Expand Up @@ -340,9 +384,9 @@ void ARX_MAGICAL_FLARES_Update() {
if(!g_magicFlaresCount)
return;

shinum++;
if(shinum >= 10) {
shinum = 1;
g_magicFlares.shinum++;
if(g_magicFlares.shinum >= 10) {
g_magicFlares.shinum = 1;
}

PlatformDuration diff = g_platformTime.lastFrameDuration();
Expand All @@ -361,7 +405,7 @@ void ARX_MAGICAL_FLARES_Update() {
case 2: surf = g_magicFlareTextures.lumignon; break;
case 3: surf = g_magicFlareTextures.lumignon2; break;
case 4: surf = g_magicFlareTextures.plasm; break;
default: surf = g_magicFlareTextures.shine[shinum]; break;
default: surf = g_magicFlareTextures.shine[g_magicFlares.shinum]; break;
}

mat.setTexture(surf);
Expand Down Expand Up @@ -392,7 +436,7 @@ void ARX_MAGICAL_FLARES_Update() {
}

if(flare.tolive <= 0 || flare.pos.y < -64.f || size < 3.f) {
removeFlare(flare);
g_magicFlares.removeFlare(flare);
continue;
}

Expand Down