Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
initial commit
  • Loading branch information
L1quid committed Jan 22, 2011
0 parents commit 923eb93
Show file tree
Hide file tree
Showing 31 changed files with 5,505 additions and 0 deletions.
Binary file added Market_Deco.ttf
Binary file not shown.
129 changes: 129 additions & 0 deletions explosivo/Emitter.cpp
@@ -0,0 +1,129 @@
#include <windows.h>
#include <math.h>
#include "Emitter.h"
#include "config.h"
#include "explosivo.h"

extern unsigned int WIDTH, HEIGHT;

Emitter::Emitter()
{
reset();
}

Emitter::~Emitter()
{
m_streamlets.Empty(true);
}

void Emitter::reset()
{
m_age = 0.0;
m_cx = m_cy = 0;
m_x_offset = m_y_offset = 0;
}

void Emitter::init_stream()
{
int i;

for (i = 0; i < STREAMLETS_PER_EMITTER; i++)
{
Streamlet *p = NULL;
p = create_streamlet();

if (!p)
break;
}
}

Streamlet *Emitter::create_streamlet()
{
Streamlet *p = NULL;
p = new Streamlet();
m_streamlets.Add(p);
m_inactive_streamlets.Add(p);

return(p);
}

void Emitter::tick()
{
bool needs_activation = m_inactive_streamlets.GetSize() > 0 && (int)m_age % FRAMES_BETWEEN_STREAMLETS == 0;

if (needs_activation)
emit();

int i, num_streamlets = m_active_streamlets.GetSize();
Streamlet *p = NULL;
POINT pos;

for (i = 0; i < num_streamlets; i++)
{
p = m_active_streamlets.Get(i);

if (!p)
continue;

p->tick();
p->get_pos(&pos);

if (pos.x >= m_win_width || pos.y >= m_win_height)
{
p->deactivate();
m_active_streamlets.Delete(m_active_streamlets.Find(p));
m_inactive_streamlets.Add(p);
}
}

m_age += AGE_INCREMENT(WIDTH);
}

bool Emitter::emit()
{
Streamlet *p = NULL;

if (m_inactive_streamlets.GetSize() == 0)
{
if (m_streamlets.GetSize() < STREAMLETS_PER_EMITTER)
p = create_streamlet();
}
else
p = m_inactive_streamlets.Get(0);

if (!p)
return(false);

p->activate();
m_inactive_streamlets.Delete(m_inactive_streamlets.Find(p));
m_active_streamlets.Add(p);

return(true);
}

void Emitter::set_window(int w, int h)
{
m_win_width = w;
m_win_height = h;
}

WDL_PtrList<Streamlet> *Emitter::get_streamlets()
{
//sort_streamlets();

return(&m_active_streamlets);
}

int STREAMLET_COMPARE(const void *a, const void *b)
{
Streamlet *aa = (Streamlet *)a;
Streamlet *bb = (Streamlet *)b;

return ((bb->get_width() + bb->get_height()) * 2 - (aa->get_width() + aa->get_height()) * 2);
}

void Emitter::sort_streamlets()
{
m_sorted_streamlets.Empty();
qsort(m_active_streamlets.GetList(), m_active_streamlets.GetSize(), sizeof(Streamlet *), STREAMLET_COMPARE);
}
32 changes: 32 additions & 0 deletions explosivo/Emitter.h
@@ -0,0 +1,32 @@
#ifndef _DEMOS_EMITTER_H
#define _DEMOS_EMITTER_H

#include "Streamlet.h"
#include "../../wdl/ptrlist.h"

class Emitter
{
public:
Emitter();
virtual ~Emitter();

void reset();
void init_stream();
Streamlet *create_streamlet();
void tick();
bool emit();
void set_window(int w, int h);
WDL_PtrList<Streamlet> *get_streamlets();
void sort_streamlets();
void set_offset(int x, int y) { m_x_offset = x; m_y_offset = y; }
int get_x_offset() const { return(m_x_offset); }
int get_y_offset() const { return(m_y_offset); }
double get_age() const { return(m_age); }

protected:
double m_age;
int m_cx, m_cy, m_win_width, m_win_height, m_x_offset, m_y_offset;
WDL_PtrList<Streamlet> m_streamlets, m_active_streamlets, m_inactive_streamlets, m_sorted_streamlets;
};

#endif // _DEMOS_EMITTER_H
144 changes: 144 additions & 0 deletions explosivo/Firework.cpp
@@ -0,0 +1,144 @@
#include "Firework.h"
#include "config.h"
#include "intel_rand.h"
#include <math.h>

Firework::Firework(int cx, int cy, int maxw, int maxh, BRUSH_COLOR base_color, BRUSH_SHAPE base_shape, int opacity, int max_radius) :
m_cx(cx), m_cy(cy), m_ww(maxw), m_wh(maxh), m_base_color(base_color), m_base_shape(base_shape), m_opacity(opacity), m_max_radius(max_radius)
{
reset();
}

Firework::~Firework()
{
free_particles();
}

void Firework::reset()
{
m_source_radius = m_max_radius * PI;
m_age = MAX_FIREWORK_AGE;
double step = (double)360.0 / (double)MAX_PARTICLES;
BRUSH_COLOR base_color = m_base_color;
m_base_shape = m_base_shape == BRUSH_SHAPE::RANDOM_BRUSH ? (BRUSH_SHAPE)(genrand64_int64() % Firework::total_shapes() - 1) : m_base_shape;

#if 1
bool reused = m_particles.GetSize() > 0;
int j = 0;

for (double i = 0.0; i <= 360.0; i += step)
{
if ((!reused ? m_particles.GetSize() : j) >= MAX_PARTICLES)
break;

double deginrad = i * PI / 180.0;
int x = cos(deginrad) * m_source_radius;
int y = sin(deginrad) * m_source_radius;
Particle *p = NULL;

if (!reused)
{
p = new Particle(m_cx + x, m_cy + y, base_color, m_opacity, m_max_radius);

if (!p)
continue;

p->m_parent = (void *)this;
m_particles.Insert(0, p);
}
else
{
p = m_particles.Get(j++);

if (!p)
continue;

p->m_cx = m_cx + x;
p->m_cy = m_cy + y;
p->m_base_color = base_color;
p->m_opacity = m_opacity;
p->reset();
}

}
#else
double a = 1.15, b = 0.15;
double pidiv = (PI / 720.0f);
for (int i = 0; i < MAX_PARTICLES; i++)
{
double ang = pidiv * i;
int x = m_cx + (a * cos(ang) * (pow(b * ang, 2.718281828)));
int y = m_cy + (a * sin(ang) * (pow(b * ang, 2.718281828)));
Particle *p = NULL;
p = new Particle(x, y, base_color);
m_particles.Insert(0, p);
}
#endif
}

void Firework::tick()
{
if (m_age-- > MAX_FIREWORK_AGE - EXPLODE_AFTER)
return;

if (MAX_FIREWORK_AGE > 0 && m_age == 0)
reset();

bool went_offscreen = false;

for (int i = 0; i < m_particles.GetSize(); i++)
{
Particle *p = m_particles.Get(i);

if (m_age % p->m_move_after == 0)
{
p->change_direction();
//p->change_size();
}

p->tick();

if ((p->m_cx < 0 || p->m_cx >= m_ww) ||
(p->m_cy < 0 || p->m_cy >= m_wh))
{
went_offscreen = true;
}
}

if (went_offscreen)
reset();
}

void Firework::free_particles()
{
m_particles.Empty(true);
}

int Firework::total_colors()
{
return(9);
}

int Firework::total_shapes()
{
return(19);
}

void Firework::set_max_radius(int max_radius)
{
m_max_radius = max_radius;

for (int i = 0; i < m_particles.GetSize(); i++)
{
Particle *p = m_particles.Get(i);
p->m_max_radius = m_max_radius;
p->change_size();
}
}

int Firework::get_max_radius()
{
return(m_max_radius);
}

0 comments on commit 923eb93

Please sign in to comment.