Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126876
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/fire.cpp b/util/fire.cpp
index 5303782e..e8fe3880 100644
--- a/util/fire.cpp
+++ b/util/fire.cpp
@@ -1,172 +1,172 @@
#include "bitmap.h"
#include <vector>
#include "fire.h"
#include <string.h>
#include "funcs.h"
#include <math.h>
class Bitmap;
namespace Paintown{
static int MAX_X = 320;
static int MAX_Y = 240;
Fire::Fire(){
Util::blend_palette(colors, 64, Bitmap::makeColor(64, 0, 0), Bitmap::makeColor(255, 0, 0));
Util::blend_palette(colors + 64, 64, Bitmap::makeColor(255, 0, 0), Bitmap::makeColor(255, 255, 0));
Util::blend_palette(colors + 64 + 64, 96, Bitmap::makeColor(255, 255, 0), Bitmap::makeColor(255, 255, 255));
Util::blend_palette(colors + 64 + 64 + 64 + 32, 32, Bitmap::makeColor(255, 255, 255), Bitmap::makeColor(255, 255, 255));
data = new unsigned char*[MAX_Y];
for (int i = 0; i < MAX_Y; i++){
data[i] = new unsigned char[MAX_X];
memset(data[i], 0, MAX_X);
}
for (int i = 0; i < MAX_HOTSPOTS; i++){
hotspots[i] = Util::rnd(MAX_X);
directions[i] = 0;
}
for (int i = 0; i < MAX_WISPS; i++){
Wisp & wisp = wisps[i];
wisp.y = MAX_Y-1 + Util::rnd(MAX_Y);
wisp.x = Util::rnd(MAX_X);
wisp.life = MAX_Y;
wisp.angle = Util::rnd(360);
}
}
void Fire::updateHotspots(){
for (int i = 0; i < MAX_HOTSPOTS; i++){
// hotspots[i] = (hotspots[i] + Util::rnd(5) - 2) % MAX_X;
hotspots[i] += directions[i];
if (hotspots[i] >= MAX_X){
hotspots[i] -= MAX_X;
}
if (hotspots[i] < 0){
hotspots[i] += MAX_X;
}
directions[i] += (double) (Util::rnd(7) - 3) / 5.0;
if (directions[i] < -4){
directions[i] = -4;
}
if (directions[i] > 4){
directions[i] = 4;
}
}
int hotspot_length = 40;
for (int i = 0; i < MAX_HOTSPOTS; i++){
for (int x = -hotspot_length/2; x < hotspot_length/2; x++){
int position = ((int) hotspots[i] + x + MAX_X) % MAX_X;
int more = (int) data[MAX_Y-1][position] + (hotspot_length / 2 - fabs(x));
if (more >= MAX_COLORS){
more = MAX_COLORS - 1;
}
data[MAX_Y-1][position] = more;
}
}
}
void Fire::updateWisps(){
for (int i = 0; i < MAX_WISPS; i++){
Wisp & wisp = wisps[i];
wisp.y -= 2;
wisp.life -= 1;
wisp.angle = (wisp.angle + 1) % 360;
if (wisp.life < 0){
wisp.y = MAX_Y-1 + Util::rnd(MAX_Y);
wisp.life = MAX_Y;
}
int my = (int) wisp.y;
int mx = (int)(wisp.x + sin(Util::radians(wisp.angle)) * 10);
if (mx < 0){
mx += MAX_X;
}
if (mx >= MAX_X){
mx -= MAX_X;
}
if (my > 0 && my < MAX_Y){
int z = data[my][mx] + wisp.life * 2;
if (z >= MAX_COLORS){
z = MAX_COLORS - 1;
}
// z = MAX_COLORS - 1;
// std::cout << "Update flicker at " << mx << ", " << my << " to " << z << std::endl;
data[my][mx] = z;
}
}
}
void Fire::update(){
updateHotspots();
// updateWisps();
int decay = 1;
// for (int y = MAX_Y-1; y > 0; y--){
for (int y = 0; y < MAX_Y; y++){
for (int x = 0; x < MAX_X; x++){
if (y < MAX_Y-1){
int lx = x-1;
if (lx < 0){
lx += MAX_X;
}
int rx = x+1;
if (rx >= MAX_X){
rx -= MAX_X;
}
// int less = (int)((double) data[y+1][x] * 0.6 + (double) data[y+1][lx] * 0.3 + (double) data[y+1][rx] * 0.3);
unsigned char * down = data[y+1];
/* dont change these numbers (0.2, 0.62, 9) because they affect
* the height of the flames. if the value of fire does not go down
* monotonically then the entire screen will be filled with flames.
*/
- int less = (double) down[lx] * 0.20;
- less += (double) down[rx] * 0.20;
- less += (double) down[x] * 0.51;
- less += (double) data[y][x] * 0.1;
- less -= Util::rnd(9);
+ int less = (double) down[lx] * 0.19;
+ less += (double) down[rx] * 0.19;
+ less += (double) down[x] * (0.4 + Util::rnd(25) / 100.0);
+ less += (double) data[y][x] * 0.10;
+ // less -= Util::rnd(15);
if (less < 0){
less = 0;
}
if (less >= MAX_COLORS){
less = MAX_COLORS - 1;
}
data[y][x] = (unsigned char) less;
} else {
int less = (int)((double) data[y][x] * 0.95);
if (less < 0){
less = 0;
}
data[y][x] = (unsigned char) less;
}
}
}
}
void Fire::draw(const Bitmap & work){
// Bitmap::drawingMode(Bitmap::MODE_TRANS);
for (int y = 0; y < MAX_Y; y++){
for (int x = 0; x < MAX_X; x++){
// work.putPixel(x, y, colors[data[y][x]]);
if (data[y][x] > 0){
work.rectangleFill(x*2, y*2, x*2+1, y*2+1, colors[data[y][x]]);
}
}
}
// Bitmap::drawingMode(Bitmap::MODE_SOLID);
}
Fire::~Fire(){
for (int y = 0; y < MAX_Y; y++){
delete[] data[y];
}
delete[] data;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 1:24 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69232
Default Alt Text
(5 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline