2019-09-19 22:42:45 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 Nuke.YKT
|
|
|
|
|
|
|
|
This file is part of NBlood.
|
|
|
|
|
|
|
|
NBlood is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-09-21 18:59:54 +00:00
|
|
|
|
|
|
|
#include "ns.h" // Must come before everything else!
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "build.h"
|
|
|
|
#include "common_game.h"
|
|
|
|
#include "blood.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
BEGIN_BLD_NS
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
int fireSize = 128;
|
|
|
|
int gDamping = 6;
|
|
|
|
|
2019-09-21 17:57:41 +00:00
|
|
|
char CoolTable[1024];
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
void CellularFrame(char *pFrame, int sizeX, int sizeY);
|
|
|
|
|
|
|
|
char FrameBuffer[17280];
|
|
|
|
char SeedBuffer[16][128];
|
2020-07-25 21:35:39 +00:00
|
|
|
static TArray<uint8_t> gCLU;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
void InitSeedBuffers(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
for (int j = 0; j < fireSize; j += 2)
|
|
|
|
SeedBuffer[i][j] = SeedBuffer[i][j+1] = wrand();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BuildCoolTable(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 1024; i++)
|
|
|
|
CoolTable[i] = ClipLow((i-gDamping) / 4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoFireFrame(void)
|
|
|
|
{
|
|
|
|
int nRand = qrand()&15;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
memcpy(FrameBuffer+16896+i*128, SeedBuffer[nRand], 128);
|
|
|
|
}
|
2019-10-14 22:54:14 +00:00
|
|
|
CellularFrame(FrameBuffer, 128, 132);
|
|
|
|
auto pData = TileFiles.tileMakeWritable(2342);
|
2019-09-19 22:42:45 +00:00
|
|
|
char *pSource = FrameBuffer;
|
|
|
|
int x = fireSize;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
int y = fireSize;
|
2019-10-11 21:31:59 +00:00
|
|
|
auto pDataBak = pData;
|
2019-09-19 22:42:45 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
*pData = gCLU[*pSource];
|
|
|
|
pSource++;
|
|
|
|
pData += fireSize;
|
|
|
|
} while (--y);
|
|
|
|
pData = pDataBak + 1;
|
|
|
|
} while (--x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FireInit(void)
|
|
|
|
{
|
|
|
|
memset(FrameBuffer, 0, sizeof(FrameBuffer));
|
|
|
|
BuildCoolTable();
|
|
|
|
InitSeedBuffers();
|
2020-07-25 21:35:39 +00:00
|
|
|
auto fr = fileSystem.OpenFileReader("rfire.clu");
|
|
|
|
if (!fr.isOpen())
|
2019-09-19 22:42:45 +00:00
|
|
|
ThrowError("RFIRE.CLU not found");
|
2020-07-25 21:35:39 +00:00
|
|
|
gCLU = fr.Read();
|
2019-09-19 22:42:45 +00:00
|
|
|
for (int i = 0; i < 100; i++)
|
|
|
|
DoFireFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FireProcess(void)
|
|
|
|
{
|
2019-09-07 13:15:39 +00:00
|
|
|
static ClockTicks lastUpdate;
|
|
|
|
if (totalclock < lastUpdate || lastUpdate + 2 < totalclock)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
DoFireFrame();
|
2019-09-07 13:15:39 +00:00
|
|
|
lastUpdate = totalclock;
|
2019-09-19 22:42:45 +00:00
|
|
|
tileInvalidate(2342, -1, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CellularFrame(char *pFrame, int sizeX, int sizeY)
|
|
|
|
{
|
|
|
|
int nSquare = sizeX * sizeY;
|
|
|
|
unsigned char *pPtr1 = (unsigned char*)pFrame;
|
|
|
|
while (nSquare--)
|
|
|
|
{
|
|
|
|
unsigned char *pPtr2 = pPtr1+sizeX;
|
|
|
|
int sum = *(pPtr2-1) + *pPtr2 + *(pPtr2+1) + *(pPtr2+sizeX);
|
|
|
|
if (*(pPtr2+sizeX) > 96)
|
|
|
|
{
|
|
|
|
pPtr2 += sizeX;
|
|
|
|
sum += *(pPtr2-1) + *pPtr2 + *(pPtr2+1) + *(pPtr2+sizeX);
|
|
|
|
sum >>= 1;
|
|
|
|
}
|
|
|
|
*pPtr1 = CoolTable[sum];
|
|
|
|
pPtr1++;
|
|
|
|
}
|
|
|
|
}
|
2019-09-22 06:39:22 +00:00
|
|
|
|
|
|
|
END_BLD_NS
|