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

added particle system frontend #194

Closed

Conversation

Eswar-S-Sethu
Copy link

Description

I implemented the frontend of the particle system using SplashKit functions. SDL backend is being developed at the moment.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Since the particle system files are separate, I tested it after building the library. All the functionalities I added worked successfully.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Copy link
Contributor

@matt439 matt439 left a comment

Choose a reason for hiding this comment

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

I like the idea of including particles in SplashKit as they could greatly enhance the visuals or gameplay of a game. In this PR there are some formatting issues to resolve as well as the need for more comprehensive documentation of the methods. The PR documentation should also be fleshed out.

I think it would help greatly to include a simple demonstration of the particle system working. It could be added to test_graphics.cpp or a similar file. That way it would be much easier to appreciate how it works.


#define MAX_PARTICLES 1000 // Maximum number of particles
#define STREAK_HISTORY 20 // Number of positions to track for the streak
#define PI 3.14 // setting the PI value
Copy link
Contributor

Choose a reason for hiding this comment

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

M_PI is defined in cmath so no need to redefine.

#define PI 3.14 // setting the PI value

// Particle structure to represent individual particle properties
struct Particle
Copy link
Contributor

Choose a reason for hiding this comment

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

Structs normally use snake_case naming in SK.

};

// Particle system to manage all particles
struct ParticleSystem
Copy link
Contributor

Choose a reason for hiding this comment

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

Snake case would be best here too.

bool glow_enabled; // Whether this particle glows
float weight; // Particle weight


Copy link
Contributor

Choose a reason for hiding this comment

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

Empty lines.

bool gravity_enabled; // Toggle for gravity
int emission_rate; // Multiplier for particles emitted per frame


Copy link
Contributor

Choose a reason for hiding this comment

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

Empty lines.


};

// Initialize the particle system
Copy link
Contributor

Choose a reason for hiding this comment

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

All of the methods below will need more comprehensive documentation. See some of the other header files for reference of the required format.

structure.txt Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this auto-generated? Would be best to not include this in the PR if its not required.

// Particle system to manage all particles
struct ParticleSystem
{
Particle particles[MAX_PARTICLES]; // Array of particles
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there always going to be the maximum number of particles? If not, std::vector could save some memory.

@matt439
Copy link
Contributor

matt439 commented Dec 6, 2024

Oh and I just realized this PR is to the main splashkit-core repository, when it should be against the Thoth Tech fork: https://github.com/thoth-tech/splashkit-core

#include <cmath>

// Initialize the particle system
void initialize_particle_system(ParticleSystem &system, double x, double y)
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialize_particle_system takes double x, double y parameters which is used to set emitter_x/y and last_x/y which are floats.

Should follow SplashKit's dynamic allocation pattern
Need to set pointer identifier on creation
particle_system create_particle_system(double x, double y)
{
particle_system result = new _particle_system_data();
result->id = PARTICLE_SYSTEM_PTR;
result->emitter_x = x;
result->emitter_y = y;
// ...
return result;
}

Add Freeing Function:
void free_particle_system(particle_system to_free)
{
if (VALID_PTR(to_free, PARTICLE_SYSTEM_PTR))
{
to_free->id = NONE_PTR;
delete(to_free);
}
}

All functions that use the particle system would need to validate the pointer:
if (!VALID_PTR(ps, PARTICLE_SYSTEM_PTR))
{
LOG(WARNING) << "Invalid particle system";
return;
}

};

// Particle system to manage all particles
struct ParticleSystem
Copy link
Contributor

@NoahJCross NoahJCross Dec 8, 2024

Choose a reason for hiding this comment

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

The particle system should use a pointer-based approach because SplashKit uses an FFI (Foreign Function Interface) to expose its functionality to other languages. Direct struct passing across the FFI boundary can be problematic due to:
Different memory layouts between languages
Different padding/alignment rules
Difficulty tracking object lifetime across language boundaries
This is why SplashKit consistently uses pointer types (like animation, sound_effect, timers, etc.) rather than passing structs directly.

Internal data structures should use snake_case with leading underscore and should add the pointer identifier for validation

struct _particle_data { ... }
struct _particle_system_data {
pointer_identifier id; // For FFI pointer validation
// ...
}
typedef _particle_system_data *particle_system;

You can also consider using:
point_2d position; // point_2d instead of separate x,y
vector_2d velocity; // vector_2d instead of separate dx,dy
vector<_particle_data> particles; // Dynamic array for flexibility
point_2d emitter_pos; // point_2d
point_2d last_pos; // point_2d
vector<point_2d> streak_positions; // vector of point_2d

float distance = sqrt(dx * dx + dy * dy);

// Skip segments with large distances (to prevent the straight line artifact)
if (distance > 50.0f) // Threshold for skipping outliers
Copy link
Contributor

Choose a reason for hiding this comment

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

50.0f may be better as a constant

Copy link
Contributor

Choose a reason for hiding this comment

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

The core functionality is solid, but my suggested changes will help it integrate better with SplashKit's FFI requirements and type consistency.

@macite
Copy link
Member

macite commented Jan 7, 2025

It looks like you have inadvertently included a large number of files that seem to be unchanged. You will need to look at this if you want this merged at some point, as we cannot accept this as it is at the moment.

@omckeon omckeon mentioned this pull request Jan 12, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants