Apply LF line endings as an SVN property, this time on the JGE source files.

This commit is contained in:
wrenczes@gmail.com
2011-01-28 06:03:52 +00:00
parent 32cabc15c2
commit f2cbd883a6
78 changed files with 23650 additions and 23650 deletions
+89 -89
View File
@@ -1,89 +1,89 @@
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeColor*** helper classes implementation
*/
#include "../../include/hge/hgecolor.h"
#include <math.h>
#ifndef min
#define min(x, y) ((x<y)?x:y)
#endif
#ifndef max
#define max(x, y) ((x>y)?x:y)
#endif
void hgeColorHSV::SetHWColor(DWORD col)
{
float r, g, b;
float minv, maxv, delta;
float del_R, del_G, del_B;
a = (col>>24) / 255.0f;
r = ((col>>16) & 0xFF) / 255.0f;
g = ((col>>8) & 0xFF) / 255.0f;
b = (col & 0xFF) / 255.0f;
minv = min(min(r, g), b);
maxv = max(max(r, g), b);
delta = maxv - minv;
v = maxv;
if (delta == 0)
{
h = 0;
s = 0;
}
else
{
s = delta / maxv;
del_R = (((maxv - r) / 6) + (delta / 2)) / delta;
del_G = (((maxv - g) / 6) + (delta / 2)) / delta;
del_B = (((maxv - b) / 6) + (delta / 2)) / delta;
if (r == maxv) {h = del_B - del_G;}
else if (g == maxv) {h = (1 / 3) + del_R - del_B;}
else if (b == maxv) {h = (2 / 3) + del_G - del_R;}
if (h < 0) h += 1;
if (h > 1) h -= 1;
}
}
DWORD hgeColorHSV::GetHWColor() const
{
float r, g, b;
float xh, i, p1, p2, p3;
if (s == 0)
{
r = v;
g = v;
b = v;
}
else
{
xh = h * 6;
if(xh == 6) xh=0;
i = floorf(xh);
p1 = v * (1 - s);
p2 = v * (1 - s * (xh - i));
p3 = v * (1 - s * (1 - (xh - i)));
if (i == 0) {r = v; g = p3; b = p1;}
else if (i == 1) {r = p2; g = v; b = p1;}
else if (i == 2) {r = p1; g = v; b = p3;}
else if (i == 3) {r = p1; g = p2; b = v; }
else if (i == 4) {r = p3; g = p1; b = v; }
else {r = v; g = p1; b = p2;}
}
return (ARGB((int)(a*255.0f), (int)(r*255.0f), (int)(g*255.0f), (int)(b*255.0f)));
}
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeColor*** helper classes implementation
*/
#include "../../include/hge/hgecolor.h"
#include <math.h>
#ifndef min
#define min(x, y) ((x<y)?x:y)
#endif
#ifndef max
#define max(x, y) ((x>y)?x:y)
#endif
void hgeColorHSV::SetHWColor(DWORD col)
{
float r, g, b;
float minv, maxv, delta;
float del_R, del_G, del_B;
a = (col>>24) / 255.0f;
r = ((col>>16) & 0xFF) / 255.0f;
g = ((col>>8) & 0xFF) / 255.0f;
b = (col & 0xFF) / 255.0f;
minv = min(min(r, g), b);
maxv = max(max(r, g), b);
delta = maxv - minv;
v = maxv;
if (delta == 0)
{
h = 0;
s = 0;
}
else
{
s = delta / maxv;
del_R = (((maxv - r) / 6) + (delta / 2)) / delta;
del_G = (((maxv - g) / 6) + (delta / 2)) / delta;
del_B = (((maxv - b) / 6) + (delta / 2)) / delta;
if (r == maxv) {h = del_B - del_G;}
else if (g == maxv) {h = (1 / 3) + del_R - del_B;}
else if (b == maxv) {h = (2 / 3) + del_G - del_R;}
if (h < 0) h += 1;
if (h > 1) h -= 1;
}
}
DWORD hgeColorHSV::GetHWColor() const
{
float r, g, b;
float xh, i, p1, p2, p3;
if (s == 0)
{
r = v;
g = v;
b = v;
}
else
{
xh = h * 6;
if(xh == 6) xh=0;
i = floorf(xh);
p1 = v * (1 - s);
p2 = v * (1 - s * (xh - i));
p3 = v * (1 - s * (1 - (xh - i)));
if (i == 0) {r = v; g = p3; b = p1;}
else if (i == 1) {r = p2; g = v; b = p1;}
else if (i == 2) {r = p1; g = v; b = p3;}
else if (i == 3) {r = p1; g = p2; b = v; }
else if (i == 4) {r = p3; g = p1; b = v; }
else {r = v; g = p1; b = p2;}
}
return (ARGB((int)(a*255.0f), (int)(r*255.0f), (int)(g*255.0f), (int)(b*255.0f)));
}
+252 -252
View File
@@ -1,252 +1,252 @@
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeDistortionMesh helper class implementation
*/
#include "../../include/JGE.h"
#include "../../include/JTypes.h"
#include "../../include/JRenderer.h"
#include "../../include/JFileSystem.h"
#include "../../include/hge/hgedistort.h"
//HGE *hgeDistortionMesh::hge=0;
hgeDistortionMesh::hgeDistortionMesh(int cols, int rows)
{
int i;
//hge=hgeCreate(HGE_VERSION);
nRows=rows;
nCols=cols;
cellw=cellh=0;
//quad.tex=0;
//quad.blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_ZWRITE;
quad = NULL;
disp_array=new Vertex[rows*cols];
for(i=0;i<rows*cols;i++)
{
disp_array[i].x=0.0f;
disp_array[i].y=0.0f;
disp_array[i].u=0.0f;
disp_array[i].v=0.0f;
disp_array[i].z=0.5f;
disp_array[i].color=ARGB(0xFF,0xFF,0xFF,0xFF);
}
}
hgeDistortionMesh::hgeDistortionMesh(const hgeDistortionMesh &dm)
{
// hge=hgeCreate(HGE_VERSION);
nRows=dm.nRows;
nCols=dm.nCols;
cellw=dm.cellw;
cellh=dm.cellh;
tx=dm.tx;
ty=dm.ty;
width=dm.width;
height=dm.height;
quad=dm.quad;
disp_array=new Vertex[nRows*nCols];
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
}
hgeDistortionMesh::~hgeDistortionMesh()
{
delete[] disp_array;
SAFE_DELETE(quad);
}
hgeDistortionMesh& hgeDistortionMesh::operator= (const hgeDistortionMesh &dm)
{
if(this!=&dm)
{
nRows=dm.nRows;
nCols=dm.nCols;
cellw=dm.cellw;
cellh=dm.cellh;
tx=dm.tx;
ty=dm.ty;
width=dm.width;
height=dm.height;
quad=dm.quad;
delete[] disp_array;
disp_array=new Vertex[nRows*nCols];
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
}
return *this;
}
void hgeDistortionMesh::SetTexture(JTexture* tex)
{
if (quad)
delete quad;
quad = new JQuad(tex, 0, 0, 16, 16);
//quad.tex=tex;
}
void hgeDistortionMesh::SetTextureRect(float x, float y, float w, float h)
{
int i,j;
float tw,th;
tx=x; ty=y; width=w; height=h;
if (quad->mTex)
{
tw=(float)quad->mTex->mTexWidth;
th=(float)quad->mTex->mTexHeight;
}
else
{
tw = w;
th = h;
}
cellw=w/(nCols-1);
cellh=h/(nRows-1);
for(j=0; j<nRows; j++)
for(i=0; i<nCols; i++)
{
disp_array[j*nCols+i].u=(x+i*cellw);
disp_array[j*nCols+i].v=(y+j*cellh);
disp_array[j*nCols+i].x=i*cellw;
disp_array[j*nCols+i].y=j*cellh;
}
}
void hgeDistortionMesh::SetBlendMode(int blend __attribute__((unused)))
{
// quad.blend=blend;
}
void hgeDistortionMesh::Clear(PIXEL_TYPE col, float z)
{
int i,j;
for(j=0; j<nRows; j++)
for(i=0; i<nCols; i++)
{
disp_array[j*nCols+i].x=i*cellw;
disp_array[j*nCols+i].y=j*cellh;
disp_array[j*nCols+i].color=col;
disp_array[j*nCols+i].z=z;
}
}
void hgeDistortionMesh::Render(float x, float y)
{
int i,j,idx;
VertexColor points[4];
JRenderer* renderer = JRenderer::GetInstance();
for(j=0; j<nRows-1; j++)
for(i=0; i<nCols-1; i++)
{
idx=j*nCols+i;
quad->SetTextureRect(disp_array[idx].u, disp_array[idx].v, cellw, cellh);
points[0].x = x+disp_array[idx+nCols].x;
points[0].y = y+disp_array[idx+nCols].y;
points[0].z = disp_array[idx+nCols].z;
points[0].color = disp_array[idx+nCols].color;
points[1].x = x+disp_array[idx+nCols+1].x;
points[1].y = y+disp_array[idx+nCols+1].y;
points[1].z = disp_array[idx+nCols+1].z;
points[1].color = disp_array[idx+nCols+1].color;
points[2].x = x+disp_array[idx+1].x;
points[2].y = y+disp_array[idx+1].y;
points[2].z = disp_array[idx+1].z;
points[2].color = disp_array[idx+1].color;
points[3].x = x+disp_array[idx].x;
points[3].y = y+disp_array[idx].y;
points[3].z = disp_array[idx].z;
points[3].color = disp_array[idx].color;
renderer->RenderQuad(quad, points);
}
}
void hgeDistortionMesh::SetZ(int col, int row, float z)
{
if(row<nRows && col<nCols) disp_array[row*nCols+col].z=z;
}
void hgeDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
{
if(row<nRows && col<nCols) disp_array[row*nCols+col].color=color;
}
void hgeDistortionMesh::SetDisplacement(int col, int row, float dx, float dy, int ref)
{
if(row<nRows && col<nCols)
{
switch(ref)
{
case HGEDISP_NODE: dx+=col*cellw; dy+=row*cellh; break;
case HGEDISP_CENTER: dx+=cellw*(nCols-1)/2;dy+=cellh*(nRows-1)/2; break;
case HGEDISP_TOPLEFT: break;
}
disp_array[row*nCols+col].x=dx;
disp_array[row*nCols+col].y=dy;
}
}
float hgeDistortionMesh::GetZ(int col, int row) const
{
if(row<nRows && col<nCols) return disp_array[row*nCols+col].z;
else return 0.0f;
}
PIXEL_TYPE hgeDistortionMesh::GetColor(int col, int row) const
{
if(row<nRows && col<nCols) return disp_array[row*nCols+col].color;
else return 0;
}
void hgeDistortionMesh::GetDisplacement(int col, int row, float *dx, float *dy, int ref) const
{
if(row<nRows && col<nCols)
{
switch(ref)
{
case HGEDISP_NODE: *dx=disp_array[row*nCols+col].x-col*cellw;
*dy=disp_array[row*nCols+col].y-row*cellh;
break;
case HGEDISP_CENTER: *dx=disp_array[row*nCols+col].x-cellw*(nCols-1)/2;
*dy=disp_array[row*nCols+col].x-cellh*(nRows-1)/2;
break;
case HGEDISP_TOPLEFT: *dx=disp_array[row*nCols+col].x;
*dy=disp_array[row*nCols+col].y;
break;
}
}
}
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeDistortionMesh helper class implementation
*/
#include "../../include/JGE.h"
#include "../../include/JTypes.h"
#include "../../include/JRenderer.h"
#include "../../include/JFileSystem.h"
#include "../../include/hge/hgedistort.h"
//HGE *hgeDistortionMesh::hge=0;
hgeDistortionMesh::hgeDistortionMesh(int cols, int rows)
{
int i;
//hge=hgeCreate(HGE_VERSION);
nRows=rows;
nCols=cols;
cellw=cellh=0;
//quad.tex=0;
//quad.blend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_ZWRITE;
quad = NULL;
disp_array=new Vertex[rows*cols];
for(i=0;i<rows*cols;i++)
{
disp_array[i].x=0.0f;
disp_array[i].y=0.0f;
disp_array[i].u=0.0f;
disp_array[i].v=0.0f;
disp_array[i].z=0.5f;
disp_array[i].color=ARGB(0xFF,0xFF,0xFF,0xFF);
}
}
hgeDistortionMesh::hgeDistortionMesh(const hgeDistortionMesh &dm)
{
// hge=hgeCreate(HGE_VERSION);
nRows=dm.nRows;
nCols=dm.nCols;
cellw=dm.cellw;
cellh=dm.cellh;
tx=dm.tx;
ty=dm.ty;
width=dm.width;
height=dm.height;
quad=dm.quad;
disp_array=new Vertex[nRows*nCols];
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
}
hgeDistortionMesh::~hgeDistortionMesh()
{
delete[] disp_array;
SAFE_DELETE(quad);
}
hgeDistortionMesh& hgeDistortionMesh::operator= (const hgeDistortionMesh &dm)
{
if(this!=&dm)
{
nRows=dm.nRows;
nCols=dm.nCols;
cellw=dm.cellw;
cellh=dm.cellh;
tx=dm.tx;
ty=dm.ty;
width=dm.width;
height=dm.height;
quad=dm.quad;
delete[] disp_array;
disp_array=new Vertex[nRows*nCols];
memcpy(disp_array, dm.disp_array, sizeof(Vertex)*nRows*nCols);
}
return *this;
}
void hgeDistortionMesh::SetTexture(JTexture* tex)
{
if (quad)
delete quad;
quad = new JQuad(tex, 0, 0, 16, 16);
//quad.tex=tex;
}
void hgeDistortionMesh::SetTextureRect(float x, float y, float w, float h)
{
int i,j;
float tw,th;
tx=x; ty=y; width=w; height=h;
if (quad->mTex)
{
tw=(float)quad->mTex->mTexWidth;
th=(float)quad->mTex->mTexHeight;
}
else
{
tw = w;
th = h;
}
cellw=w/(nCols-1);
cellh=h/(nRows-1);
for(j=0; j<nRows; j++)
for(i=0; i<nCols; i++)
{
disp_array[j*nCols+i].u=(x+i*cellw);
disp_array[j*nCols+i].v=(y+j*cellh);
disp_array[j*nCols+i].x=i*cellw;
disp_array[j*nCols+i].y=j*cellh;
}
}
void hgeDistortionMesh::SetBlendMode(int blend __attribute__((unused)))
{
// quad.blend=blend;
}
void hgeDistortionMesh::Clear(PIXEL_TYPE col, float z)
{
int i,j;
for(j=0; j<nRows; j++)
for(i=0; i<nCols; i++)
{
disp_array[j*nCols+i].x=i*cellw;
disp_array[j*nCols+i].y=j*cellh;
disp_array[j*nCols+i].color=col;
disp_array[j*nCols+i].z=z;
}
}
void hgeDistortionMesh::Render(float x, float y)
{
int i,j,idx;
VertexColor points[4];
JRenderer* renderer = JRenderer::GetInstance();
for(j=0; j<nRows-1; j++)
for(i=0; i<nCols-1; i++)
{
idx=j*nCols+i;
quad->SetTextureRect(disp_array[idx].u, disp_array[idx].v, cellw, cellh);
points[0].x = x+disp_array[idx+nCols].x;
points[0].y = y+disp_array[idx+nCols].y;
points[0].z = disp_array[idx+nCols].z;
points[0].color = disp_array[idx+nCols].color;
points[1].x = x+disp_array[idx+nCols+1].x;
points[1].y = y+disp_array[idx+nCols+1].y;
points[1].z = disp_array[idx+nCols+1].z;
points[1].color = disp_array[idx+nCols+1].color;
points[2].x = x+disp_array[idx+1].x;
points[2].y = y+disp_array[idx+1].y;
points[2].z = disp_array[idx+1].z;
points[2].color = disp_array[idx+1].color;
points[3].x = x+disp_array[idx].x;
points[3].y = y+disp_array[idx].y;
points[3].z = disp_array[idx].z;
points[3].color = disp_array[idx].color;
renderer->RenderQuad(quad, points);
}
}
void hgeDistortionMesh::SetZ(int col, int row, float z)
{
if(row<nRows && col<nCols) disp_array[row*nCols+col].z=z;
}
void hgeDistortionMesh::SetColor(int col, int row, PIXEL_TYPE color)
{
if(row<nRows && col<nCols) disp_array[row*nCols+col].color=color;
}
void hgeDistortionMesh::SetDisplacement(int col, int row, float dx, float dy, int ref)
{
if(row<nRows && col<nCols)
{
switch(ref)
{
case HGEDISP_NODE: dx+=col*cellw; dy+=row*cellh; break;
case HGEDISP_CENTER: dx+=cellw*(nCols-1)/2;dy+=cellh*(nRows-1)/2; break;
case HGEDISP_TOPLEFT: break;
}
disp_array[row*nCols+col].x=dx;
disp_array[row*nCols+col].y=dy;
}
}
float hgeDistortionMesh::GetZ(int col, int row) const
{
if(row<nRows && col<nCols) return disp_array[row*nCols+col].z;
else return 0.0f;
}
PIXEL_TYPE hgeDistortionMesh::GetColor(int col, int row) const
{
if(row<nRows && col<nCols) return disp_array[row*nCols+col].color;
else return 0;
}
void hgeDistortionMesh::GetDisplacement(int col, int row, float *dx, float *dy, int ref) const
{
if(row<nRows && col<nCols)
{
switch(ref)
{
case HGEDISP_NODE: *dx=disp_array[row*nCols+col].x-col*cellw;
*dy=disp_array[row*nCols+col].y-row*cellh;
break;
case HGEDISP_CENTER: *dx=disp_array[row*nCols+col].x-cellw*(nCols-1)/2;
*dy=disp_array[row*nCols+col].x-cellh*(nRows-1)/2;
break;
case HGEDISP_TOPLEFT: *dx=disp_array[row*nCols+col].x;
*dy=disp_array[row*nCols+col].y;
break;
}
}
}
+360 -360
View File
@@ -1,360 +1,360 @@
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeFont helper class implementation
*/
#include "../../include/JGE.h"
#include "../../include/JTypes.h"
#include "../../include/JRenderer.h"
#include "../../include/JFileSystem.h"
#include "../../include/hge/hgefont.h"
#include <stdlib.h>
#include <stdio.h>
const char FNTHEADERTAG[] = "[HGEFONT]";
const char FNTBITMAPTAG[] = "Bitmap";
const char FNTCHARTAG[] = "Char";
//HGE *hgeFont::hge=0;
char hgeFont::buffer[256];
hgeFont::hgeFont(const char *szFont, bool bMipmap __attribute__((unused)))
{
//void *data;
DWORD size;
char *desc, *pdesc;
char linebuf[256];
char buf[512], *pbuf;
char chr;
int i, x, y, w, h, a, c;
// Setup variables
//hge=hgeCreate(HGE_VERSION);
fHeight=0.0f;
fScale=1.0f;
fProportion=1.0f;
fRot=0.0f;
fTracking=0.0f;
fSpacing=1.0f;
hTexture=0;
fZ=0.5f;
//nBlend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
dwCol=ARGB(0xFF,0xFF,0xFF,0xFF);
memset( &letters, 0, sizeof(letters) );
memset( &pre, 0, sizeof(letters) );
memset( &post, 0, sizeof(letters) );
// Load font description
JFileSystem* fileSys = JFileSystem::GetInstance();
if (!fileSys->OpenFile(szFont)) return;
//data=hge->Resource_Load(szFont, &size);
//if(!data) return;
size = fileSys->GetFileSize();
desc = new char[size+1];
//memcpy(desc,data,size);
fileSys->ReadFile(desc, size);
desc[size]=0;
//hge->Resource_Free(data);
fileSys->CloseFile();
pdesc=_get_line(desc,linebuf);
if(strcmp(linebuf, FNTHEADERTAG))
{
// hge->System_Log("Font %s has incorrect format.", szFont);
delete[] desc;
return;
}
// Parse font description
JRenderer* renderer = JRenderer::GetInstance();
while((pdesc = _get_line(pdesc,linebuf))!=NULL)
{
if(!strncmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG)-1 ))
{
strcpy(buf,szFont);
pbuf=strrchr(buf,'\\');
if(!pbuf) pbuf=strrchr(buf,'/');
if(!pbuf) pbuf=buf;
else pbuf++;
if(!sscanf(linebuf, "Bitmap = %s", pbuf)) continue;
//hTexture=hge->Texture_Load(buf, 0, bMipmap);
hTexture = renderer->LoadTexture(buf);
if(!hTexture)
{
delete[] desc;
return;
}
}
else if(!strncmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG)-1 ))
{
pbuf=strchr(linebuf,'=');
if(!pbuf) continue;
pbuf++;
while(*pbuf==' ') pbuf++;
if(*pbuf=='\"')
{
pbuf++;
i=(unsigned char)*pbuf++;
pbuf++; // skip "
}
else
{
i=0;
while((*pbuf>='0' && *pbuf<='9') || (*pbuf>='A' && *pbuf<='F') || (*pbuf>='a' && *pbuf<='f'))
{
chr=*pbuf;
if(chr >= 'a') chr-='a'-':';
if(chr >= 'A') chr-='A'-':';
chr-='0';
if(chr>0xF) chr=0xF;
i=(i << 4) | chr;
pbuf++;
}
if(i<0 || i>255) continue;
}
sscanf(pbuf, " , %d , %d , %d , %d , %d , %d", &x, &y, &w, &h, &a, &c);
letters[i] = new JQuad(hTexture, (float)x, (float)y, (float)w, (float)h);
pre[i]=(float)a;
post[i]=(float)c;
if(h>fHeight) fHeight=(float)h;
}
}
delete[] desc;
}
hgeFont::~hgeFont()
{
for(int i=0; i<256; i++)
if(letters[i]) delete letters[i];
if(hTexture) delete hTexture;
//hge->Release();
}
void hgeFont::Render(float x, float y, int align, const char *string)
{
int i;
float fx=x;
JRenderer* renderer = JRenderer::GetInstance();
align &= HGETEXT_HORZMASK;
if(align==HGETEXT_RIGHT) fx-=GetStringWidth(string);
if(align==HGETEXT_CENTER) fx-=int(GetStringWidth(string)/2.0f);
while(*string)
{
if(*string=='\n')
{
y += int(fHeight*fScale*fSpacing);
fx = x;
if(align == HGETEXT_RIGHT) fx -= GetStringWidth(string+1);
if(align == HGETEXT_CENTER) fx -= int(GetStringWidth(string+1)/2.0f);
}
else
{
i=(unsigned char)*string;
if(!letters[i]) i='?';
if(letters[i])
{
fx += pre[i]*fScale*fProportion;
//letters[i]->RenderEx(fx, y, fRot, fScale*fProportion, fScale);
renderer->RenderQuad(letters[i], fx, y, fRot, fScale*fProportion, fScale);
fx += (letters[i]->mWidth+post[i]+fTracking)*fScale*fProportion;
}
}
string++;
}
}
void hgeFont::printf(float x, float y, int align, const char *format, ...)
{
//char *pArg=(char *) &format+sizeof(format);
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
//buffer[sizeof(buffer)-1]=0;
//vsprintf(buffer, format, pArg);
va_list list;
va_start(list, format);
vsprintf(buffer, format, list);
va_end(list);
Render(x,y,align,buffer);
}
void hgeFont::printfb(float x, float y, float w, float h, int align, const char *format, ...)
{
char chr, *pbuf, *prevword, *linestart;
int i,lines=0;
float tx, ty, hh, ww;
//char *pArg=(char *) &format+sizeof(format);
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
//buffer[sizeof(buffer)-1]=0;
//vsprintf(buffer, format, pArg);
va_list list;
va_start(list, format);
vsprintf(buffer, format, list);
va_end(list);
linestart=buffer;
pbuf=buffer;
prevword=0;
for(;;)
{
i=0;
while(pbuf[i] && pbuf[i]!=' ' && pbuf[i]!='\n') i++;
chr=pbuf[i];
pbuf[i]=0;
ww=GetStringWidth(linestart);
pbuf[i]=chr;
if(ww > w)
{
if(pbuf==linestart)
{
pbuf[i]='\n';
linestart=&pbuf[i+1];
}
else
{
*prevword='\n';
linestart=prevword+1;
}
lines++;
}
if(pbuf[i]=='\n')
{
prevword=&pbuf[i];
linestart=&pbuf[i+1];
pbuf=&pbuf[i+1];
lines++;
continue;
}
if(!pbuf[i]) {lines++;break;}
prevword=&pbuf[i];
pbuf=&pbuf[i+1];
}
tx=x;
ty=y;
hh=fHeight*fSpacing*fScale*lines;
switch(align & HGETEXT_HORZMASK)
{
case HGETEXT_LEFT: break;
case HGETEXT_RIGHT: tx+=w; break;
case HGETEXT_CENTER: tx+=int(w/2); break;
}
switch(align & HGETEXT_VERTMASK)
{
case HGETEXT_TOP: break;
case HGETEXT_BOTTOM: ty+=h-hh; break;
case HGETEXT_MIDDLE: ty+=int((h-hh)/2); break;
}
Render(tx,ty,align,buffer);
}
float hgeFont::GetStringWidth(const char *string) const
{
int i;
float linew, w = 0;
while(*string)
{
linew = 0;
while(*string && *string != '\n')
{
i=(unsigned char)*string;
if(!letters[i]) i='?';
if(letters[i])
linew += letters[i]->mWidth + pre[i] + post[i] + fTracking;
string++;
}
if(linew > w) w = linew;
while (*string == '\n' || *string == '\r') string++;
}
return w*fScale*fProportion;
}
void hgeFont::SetColor(PIXEL_TYPE col)
{
dwCol = col;
for(int i=0; i<256; i++)
if(letters[i])
letters[i]->SetColor(col);
}
void hgeFont::SetZ(float z)
{
fZ = z;
//for(int i=0; i<256; i++)
// if(letters[i])
// letters[i]->SetZ(z);
}
void hgeFont::SetBlendMode(int blend)
{
nBlend = blend;
//for(int i=0; i<256; i++)
// if(letters[i])
// letters[i]->SetBlendMode(blend);
}
char *hgeFont::_get_line(char *file, char *line)
{
int i=0;
if(!file[i]) return 0;
while(file[i] && file[i]!='\n' && file[i]!='\r')
{
line[i]=file[i];
i++;
}
line[i]=0;
while(file[i] && (file[i]=='\n' || file[i]=='\r')) i++;
return file + i;
}
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeFont helper class implementation
*/
#include "../../include/JGE.h"
#include "../../include/JTypes.h"
#include "../../include/JRenderer.h"
#include "../../include/JFileSystem.h"
#include "../../include/hge/hgefont.h"
#include <stdlib.h>
#include <stdio.h>
const char FNTHEADERTAG[] = "[HGEFONT]";
const char FNTBITMAPTAG[] = "Bitmap";
const char FNTCHARTAG[] = "Char";
//HGE *hgeFont::hge=0;
char hgeFont::buffer[256];
hgeFont::hgeFont(const char *szFont, bool bMipmap __attribute__((unused)))
{
//void *data;
DWORD size;
char *desc, *pdesc;
char linebuf[256];
char buf[512], *pbuf;
char chr;
int i, x, y, w, h, a, c;
// Setup variables
//hge=hgeCreate(HGE_VERSION);
fHeight=0.0f;
fScale=1.0f;
fProportion=1.0f;
fRot=0.0f;
fTracking=0.0f;
fSpacing=1.0f;
hTexture=0;
fZ=0.5f;
//nBlend=BLEND_COLORMUL | BLEND_ALPHABLEND | BLEND_NOZWRITE;
dwCol=ARGB(0xFF,0xFF,0xFF,0xFF);
memset( &letters, 0, sizeof(letters) );
memset( &pre, 0, sizeof(letters) );
memset( &post, 0, sizeof(letters) );
// Load font description
JFileSystem* fileSys = JFileSystem::GetInstance();
if (!fileSys->OpenFile(szFont)) return;
//data=hge->Resource_Load(szFont, &size);
//if(!data) return;
size = fileSys->GetFileSize();
desc = new char[size+1];
//memcpy(desc,data,size);
fileSys->ReadFile(desc, size);
desc[size]=0;
//hge->Resource_Free(data);
fileSys->CloseFile();
pdesc=_get_line(desc,linebuf);
if(strcmp(linebuf, FNTHEADERTAG))
{
// hge->System_Log("Font %s has incorrect format.", szFont);
delete[] desc;
return;
}
// Parse font description
JRenderer* renderer = JRenderer::GetInstance();
while((pdesc = _get_line(pdesc,linebuf))!=NULL)
{
if(!strncmp(linebuf, FNTBITMAPTAG, sizeof(FNTBITMAPTAG)-1 ))
{
strcpy(buf,szFont);
pbuf=strrchr(buf,'\\');
if(!pbuf) pbuf=strrchr(buf,'/');
if(!pbuf) pbuf=buf;
else pbuf++;
if(!sscanf(linebuf, "Bitmap = %s", pbuf)) continue;
//hTexture=hge->Texture_Load(buf, 0, bMipmap);
hTexture = renderer->LoadTexture(buf);
if(!hTexture)
{
delete[] desc;
return;
}
}
else if(!strncmp(linebuf, FNTCHARTAG, sizeof(FNTCHARTAG)-1 ))
{
pbuf=strchr(linebuf,'=');
if(!pbuf) continue;
pbuf++;
while(*pbuf==' ') pbuf++;
if(*pbuf=='\"')
{
pbuf++;
i=(unsigned char)*pbuf++;
pbuf++; // skip "
}
else
{
i=0;
while((*pbuf>='0' && *pbuf<='9') || (*pbuf>='A' && *pbuf<='F') || (*pbuf>='a' && *pbuf<='f'))
{
chr=*pbuf;
if(chr >= 'a') chr-='a'-':';
if(chr >= 'A') chr-='A'-':';
chr-='0';
if(chr>0xF) chr=0xF;
i=(i << 4) | chr;
pbuf++;
}
if(i<0 || i>255) continue;
}
sscanf(pbuf, " , %d , %d , %d , %d , %d , %d", &x, &y, &w, &h, &a, &c);
letters[i] = new JQuad(hTexture, (float)x, (float)y, (float)w, (float)h);
pre[i]=(float)a;
post[i]=(float)c;
if(h>fHeight) fHeight=(float)h;
}
}
delete[] desc;
}
hgeFont::~hgeFont()
{
for(int i=0; i<256; i++)
if(letters[i]) delete letters[i];
if(hTexture) delete hTexture;
//hge->Release();
}
void hgeFont::Render(float x, float y, int align, const char *string)
{
int i;
float fx=x;
JRenderer* renderer = JRenderer::GetInstance();
align &= HGETEXT_HORZMASK;
if(align==HGETEXT_RIGHT) fx-=GetStringWidth(string);
if(align==HGETEXT_CENTER) fx-=int(GetStringWidth(string)/2.0f);
while(*string)
{
if(*string=='\n')
{
y += int(fHeight*fScale*fSpacing);
fx = x;
if(align == HGETEXT_RIGHT) fx -= GetStringWidth(string+1);
if(align == HGETEXT_CENTER) fx -= int(GetStringWidth(string+1)/2.0f);
}
else
{
i=(unsigned char)*string;
if(!letters[i]) i='?';
if(letters[i])
{
fx += pre[i]*fScale*fProportion;
//letters[i]->RenderEx(fx, y, fRot, fScale*fProportion, fScale);
renderer->RenderQuad(letters[i], fx, y, fRot, fScale*fProportion, fScale);
fx += (letters[i]->mWidth+post[i]+fTracking)*fScale*fProportion;
}
}
string++;
}
}
void hgeFont::printf(float x, float y, int align, const char *format, ...)
{
//char *pArg=(char *) &format+sizeof(format);
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
//buffer[sizeof(buffer)-1]=0;
//vsprintf(buffer, format, pArg);
va_list list;
va_start(list, format);
vsprintf(buffer, format, list);
va_end(list);
Render(x,y,align,buffer);
}
void hgeFont::printfb(float x, float y, float w, float h, int align, const char *format, ...)
{
char chr, *pbuf, *prevword, *linestart;
int i,lines=0;
float tx, ty, hh, ww;
//char *pArg=(char *) &format+sizeof(format);
//_vsnprintf(buffer, sizeof(buffer)-1, format, pArg);
//buffer[sizeof(buffer)-1]=0;
//vsprintf(buffer, format, pArg);
va_list list;
va_start(list, format);
vsprintf(buffer, format, list);
va_end(list);
linestart=buffer;
pbuf=buffer;
prevword=0;
for(;;)
{
i=0;
while(pbuf[i] && pbuf[i]!=' ' && pbuf[i]!='\n') i++;
chr=pbuf[i];
pbuf[i]=0;
ww=GetStringWidth(linestart);
pbuf[i]=chr;
if(ww > w)
{
if(pbuf==linestart)
{
pbuf[i]='\n';
linestart=&pbuf[i+1];
}
else
{
*prevword='\n';
linestart=prevword+1;
}
lines++;
}
if(pbuf[i]=='\n')
{
prevword=&pbuf[i];
linestart=&pbuf[i+1];
pbuf=&pbuf[i+1];
lines++;
continue;
}
if(!pbuf[i]) {lines++;break;}
prevword=&pbuf[i];
pbuf=&pbuf[i+1];
}
tx=x;
ty=y;
hh=fHeight*fSpacing*fScale*lines;
switch(align & HGETEXT_HORZMASK)
{
case HGETEXT_LEFT: break;
case HGETEXT_RIGHT: tx+=w; break;
case HGETEXT_CENTER: tx+=int(w/2); break;
}
switch(align & HGETEXT_VERTMASK)
{
case HGETEXT_TOP: break;
case HGETEXT_BOTTOM: ty+=h-hh; break;
case HGETEXT_MIDDLE: ty+=int((h-hh)/2); break;
}
Render(tx,ty,align,buffer);
}
float hgeFont::GetStringWidth(const char *string) const
{
int i;
float linew, w = 0;
while(*string)
{
linew = 0;
while(*string && *string != '\n')
{
i=(unsigned char)*string;
if(!letters[i]) i='?';
if(letters[i])
linew += letters[i]->mWidth + pre[i] + post[i] + fTracking;
string++;
}
if(linew > w) w = linew;
while (*string == '\n' || *string == '\r') string++;
}
return w*fScale*fProportion;
}
void hgeFont::SetColor(PIXEL_TYPE col)
{
dwCol = col;
for(int i=0; i<256; i++)
if(letters[i])
letters[i]->SetColor(col);
}
void hgeFont::SetZ(float z)
{
fZ = z;
//for(int i=0; i<256; i++)
// if(letters[i])
// letters[i]->SetZ(z);
}
void hgeFont::SetBlendMode(int blend)
{
nBlend = blend;
//for(int i=0; i<256; i++)
// if(letters[i])
// letters[i]->SetBlendMode(blend);
}
char *hgeFont::_get_line(char *file, char *line)
{
int i=0;
if(!file[i]) return 0;
while(file[i] && file[i]!='\n' && file[i]!='\r')
{
line[i]=file[i];
i++;
}
line[i]=0;
while(file[i] && (file[i]=='\n' || file[i]=='\r')) i++;
return file + i;
}
+306 -306
View File
@@ -1,306 +1,306 @@
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeParticleSystem helper class implementation
*/
#include "../../include/JGE.h"
#include "../../include/JTypes.h"
#include "../../include/JRenderer.h"
#include "../../include/JFileSystem.h"
#include "../../include/hge/hgeparticle.h"
//HGE *hgeParticleSystem::hge=0;
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** Core functions implementation: random number generation
*/
unsigned int g_seed=0;
void Random_Seed(int seed)
{
if(!seed) g_seed=JGE::GetInstance()->GetTime();
else g_seed=seed;
}
int Random_Int(int min, int max)
{
g_seed=214013*g_seed+2531011;
return min+(g_seed ^ g_seed>>15)%(max-min+1);
}
float Random_Float(float min, float max)
{
g_seed=214013*g_seed+2531011;
return min+(g_seed>>16)*(1.0f/65535.0f)*(max-min);
}
hgeParticleSystem::hgeParticleSystem(const char *filename, JQuad *sprite)
{
//void *psi;
//hgeParticleSystemInfo psi;
JFileSystem* fileSys = JFileSystem::GetInstance();
//hge=hgeCreate(HGE_VERSION);
//psi=hge->Resource_Load(filename);
if (!fileSys->OpenFile(filename)) return;
//if(!psi) return;
//memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
//hge->Resource_Free(psi);
// Skip reading the pointer as it may be larger than 4 bytes in the structure
void *dummyPointer;
fileSys->ReadFile(&dummyPointer, 4);
// we're actually trying to read more than the file size now, but it's no problem.
// Note that this fix is only to avoid the largest problems, filling a structure
// by directly reading a file, is really a bad idea ...
fileSys->ReadFile(&(info.nEmission), sizeof(hgeParticleSystemInfo));
fileSys->CloseFile();
info.sprite=sprite;
// info.fGravityMin *= 100;
// info.fGravityMax *= 100;
// info.fSpeedMin *= 100;
// info.fSpeedMax *= 100;
vecLocation.x=vecPrevLocation.x=0.0f;
vecLocation.y=vecPrevLocation.y=0.0f;
fTx=fTy=0;
fEmissionResidue=0.0f;
nParticlesAlive=0;
fAge=-2.0;
mTimer = 0.0f;
rectBoundingBox.Clear();
bUpdateBoundingBox=false;
}
hgeParticleSystem::hgeParticleSystem(hgeParticleSystemInfo *psi)
{
//hge=hgeCreate(HGE_VERSION);
memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
vecLocation.x=vecPrevLocation.x=0.0f;
vecLocation.y=vecPrevLocation.y=0.0f;
fTx=fTy=0;
fEmissionResidue=0.0f;
nParticlesAlive=0;
fAge=-2.0;
mTimer = 0.0f;
rectBoundingBox.Clear();
bUpdateBoundingBox=false;
}
hgeParticleSystem::hgeParticleSystem(const hgeParticleSystem &ps)
{
memcpy(this, &ps, sizeof(hgeParticleSystem));
//hge=hgeCreate(HGE_VERSION);
}
void hgeParticleSystem::Update(float fDeltaTime)
{
int i;
float ang;
hgeVector vecAccel, vecAccel2;
if(fAge >= 0)
{
fAge += fDeltaTime;
if(fAge >= info.fLifetime) fAge = -2.0f;
}
mTimer += fDeltaTime;
if (mTimer < 0.01f)
return;
fDeltaTime = mTimer;
mTimer = 0.0f;
// update all alive particles
if(bUpdateBoundingBox) rectBoundingBox.Clear();
ParticleBuffer::iterator particle = mParticleBuffer.begin();
while(particle != mParticleBuffer.end())
{
particle->fAge += fDeltaTime;
if(particle->fAge >= particle->fTerminalAge)
{
nParticlesAlive--;
++particle;
mParticleBuffer.pop_front();
continue;
}
vecAccel = particle->vecLocation-vecLocation;
vecAccel.Normalize();
vecAccel2 = vecAccel;
vecAccel *= particle->fRadialAccel;
// vecAccel2.Rotate(M_PI_2);
// the following is faster
ang = vecAccel2.x;
vecAccel2.x = -vecAccel2.y;
vecAccel2.y = ang;
vecAccel2 *= particle->fTangentialAccel;
particle->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
particle->vecVelocity.y += particle->fGravity*fDeltaTime;
//par->vecVelocity.y = 0.1f;
particle->vecLocation += particle->vecVelocity;
particle->fSpin += particle->fSpinDelta*fDeltaTime;
particle->fSize += particle->fSizeDelta*fDeltaTime;
particle->colColor += particle->colColorDelta*fDeltaTime;
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(particle->vecLocation.x, particle->vecLocation.y);
++particle;
}
// generate new particles
if(fAge != -2.0f)
{
float fParticlesNeeded = info.nEmission*fDeltaTime + fEmissionResidue;
int nParticlesCreated = (unsigned int)fParticlesNeeded;
fEmissionResidue=fParticlesNeeded-nParticlesCreated;
for(i=0; i<nParticlesCreated; i++)
{
if(nParticlesAlive>=MAX_PARTICLES) break;
hgeParticle newParticle;
newParticle.fAge = 0.0f;
newParticle.fTerminalAge = Random_Float(info.fParticleLifeMin, info.fParticleLifeMax);
newParticle.vecLocation = vecPrevLocation+(vecLocation-vecPrevLocation)*Random_Float(0.0f, 1.0f);
newParticle.vecLocation.x += Random_Float(-2.0f, 2.0f);
newParticle.vecLocation.y += Random_Float(-2.0f, 2.0f);
ang=info.fDirection-M_PI_2+Random_Float(0,info.fSpread)-info.fSpread/2.0f;
if(info.bRelative) ang += (vecPrevLocation-vecLocation).Angle()+M_PI_2;
newParticle.vecVelocity.x = cosf(ang);
newParticle.vecVelocity.y = sinf(ang);
newParticle.vecVelocity *= Random_Float(info.fSpeedMin, info.fSpeedMax);
newParticle.fGravity = Random_Float(info.fGravityMin, info.fGravityMax);
newParticle.fRadialAccel = Random_Float(info.fRadialAccelMin, info.fRadialAccelMax);
newParticle.fTangentialAccel = Random_Float(info.fTangentialAccelMin, info.fTangentialAccelMax);
newParticle.fSize = Random_Float(info.fSizeStart, info.fSizeStart+(info.fSizeEnd-info.fSizeStart)*info.fSizeVar);
newParticle.fSizeDelta = (info.fSizeEnd-newParticle.fSize) / newParticle.fTerminalAge;
newParticle.fSpin = Random_Float(info.fSpinStart, info.fSpinStart+(info.fSpinEnd-info.fSpinStart)*info.fSpinVar);
newParticle.fSpinDelta = (info.fSpinEnd-newParticle.fSpin) / newParticle.fTerminalAge;
newParticle.colColor.r = Random_Float(info.colColorStart.r, info.colColorStart.r+(info.colColorEnd.r-info.colColorStart.r)*info.fColorVar);
newParticle.colColor.g = Random_Float(info.colColorStart.g, info.colColorStart.g+(info.colColorEnd.g-info.colColorStart.g)*info.fColorVar);
newParticle.colColor.b = Random_Float(info.colColorStart.b, info.colColorStart.b+(info.colColorEnd.b-info.colColorStart.b)*info.fColorVar);
newParticle.colColor.a = Random_Float(info.colColorStart.a, info.colColorStart.a+(info.colColorEnd.a-info.colColorStart.a)*info.fAlphaVar);
newParticle.colColorDelta.r = (info.colColorEnd.r-newParticle.colColor.r) / newParticle.fTerminalAge;
newParticle.colColorDelta.g = (info.colColorEnd.g-newParticle.colColor.g) / newParticle.fTerminalAge;
newParticle.colColorDelta.b = (info.colColorEnd.b-newParticle.colColor.b) / newParticle.fTerminalAge;
newParticle.colColorDelta.a = (info.colColorEnd.a-newParticle.colColor.a) / newParticle.fTerminalAge;
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(newParticle.vecLocation.x, newParticle.vecLocation.y);
mParticleBuffer.push_back(newParticle);
++nParticlesAlive;
}
}
vecPrevLocation=vecLocation;
}
void hgeParticleSystem::MoveTo(float x, float y, bool bMoveParticles)
{
float dx,dy;
if(bMoveParticles)
{
dx=x-vecLocation.x;
dy=y-vecLocation.y;
ParticleBuffer::iterator particle = mParticleBuffer.begin();
for (; particle != mParticleBuffer.end(); ++particle)
{
particle->vecLocation.x += dx;
particle->vecLocation.y += dy;
}
vecPrevLocation.x=vecPrevLocation.x + dx;
vecPrevLocation.y=vecPrevLocation.y + dy;
}
else
{
if(fAge==-2.0) { vecPrevLocation.x=x; vecPrevLocation.y=y; }
else { vecPrevLocation.x=vecLocation.x; vecPrevLocation.y=vecLocation.y; }
}
vecLocation.x=x;
vecLocation.y=y;
}
void hgeParticleSystem::FireAt(float x, float y)
{
Stop();
MoveTo(x,y);
Fire();
}
void hgeParticleSystem::Fire()
{
mTimer = 0.0f;
if(info.fLifetime==-1.0f) fAge=-1.0f;
else fAge=0.0f;
}
void hgeParticleSystem::Stop(bool bKillParticles)
{
fAge=-2.0f;
if(bKillParticles)
{
nParticlesAlive=0;
mParticleBuffer.clear();
rectBoundingBox.Clear();
}
}
void hgeParticleSystem::Render()
{
ParticleBuffer::iterator particle = mParticleBuffer.begin();
for (;particle != mParticleBuffer.end(); ++particle)
{
info.sprite->SetColor(particle->colColor.GetHWColor());
JRenderer::GetInstance()->RenderQuad(
info.sprite,
particle->vecLocation.x+fTx, particle->vecLocation.y+fTy,
particle->fSpin * particle->fAge,
particle->fSize, particle->fSize);
}
}
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeParticleSystem helper class implementation
*/
#include "../../include/JGE.h"
#include "../../include/JTypes.h"
#include "../../include/JRenderer.h"
#include "../../include/JFileSystem.h"
#include "../../include/hge/hgeparticle.h"
//HGE *hgeParticleSystem::hge=0;
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** Core functions implementation: random number generation
*/
unsigned int g_seed=0;
void Random_Seed(int seed)
{
if(!seed) g_seed=JGE::GetInstance()->GetTime();
else g_seed=seed;
}
int Random_Int(int min, int max)
{
g_seed=214013*g_seed+2531011;
return min+(g_seed ^ g_seed>>15)%(max-min+1);
}
float Random_Float(float min, float max)
{
g_seed=214013*g_seed+2531011;
return min+(g_seed>>16)*(1.0f/65535.0f)*(max-min);
}
hgeParticleSystem::hgeParticleSystem(const char *filename, JQuad *sprite)
{
//void *psi;
//hgeParticleSystemInfo psi;
JFileSystem* fileSys = JFileSystem::GetInstance();
//hge=hgeCreate(HGE_VERSION);
//psi=hge->Resource_Load(filename);
if (!fileSys->OpenFile(filename)) return;
//if(!psi) return;
//memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
//hge->Resource_Free(psi);
// Skip reading the pointer as it may be larger than 4 bytes in the structure
void *dummyPointer;
fileSys->ReadFile(&dummyPointer, 4);
// we're actually trying to read more than the file size now, but it's no problem.
// Note that this fix is only to avoid the largest problems, filling a structure
// by directly reading a file, is really a bad idea ...
fileSys->ReadFile(&(info.nEmission), sizeof(hgeParticleSystemInfo));
fileSys->CloseFile();
info.sprite=sprite;
// info.fGravityMin *= 100;
// info.fGravityMax *= 100;
// info.fSpeedMin *= 100;
// info.fSpeedMax *= 100;
vecLocation.x=vecPrevLocation.x=0.0f;
vecLocation.y=vecPrevLocation.y=0.0f;
fTx=fTy=0;
fEmissionResidue=0.0f;
nParticlesAlive=0;
fAge=-2.0;
mTimer = 0.0f;
rectBoundingBox.Clear();
bUpdateBoundingBox=false;
}
hgeParticleSystem::hgeParticleSystem(hgeParticleSystemInfo *psi)
{
//hge=hgeCreate(HGE_VERSION);
memcpy(&info, psi, sizeof(hgeParticleSystemInfo));
vecLocation.x=vecPrevLocation.x=0.0f;
vecLocation.y=vecPrevLocation.y=0.0f;
fTx=fTy=0;
fEmissionResidue=0.0f;
nParticlesAlive=0;
fAge=-2.0;
mTimer = 0.0f;
rectBoundingBox.Clear();
bUpdateBoundingBox=false;
}
hgeParticleSystem::hgeParticleSystem(const hgeParticleSystem &ps)
{
memcpy(this, &ps, sizeof(hgeParticleSystem));
//hge=hgeCreate(HGE_VERSION);
}
void hgeParticleSystem::Update(float fDeltaTime)
{
int i;
float ang;
hgeVector vecAccel, vecAccel2;
if(fAge >= 0)
{
fAge += fDeltaTime;
if(fAge >= info.fLifetime) fAge = -2.0f;
}
mTimer += fDeltaTime;
if (mTimer < 0.01f)
return;
fDeltaTime = mTimer;
mTimer = 0.0f;
// update all alive particles
if(bUpdateBoundingBox) rectBoundingBox.Clear();
ParticleBuffer::iterator particle = mParticleBuffer.begin();
while(particle != mParticleBuffer.end())
{
particle->fAge += fDeltaTime;
if(particle->fAge >= particle->fTerminalAge)
{
nParticlesAlive--;
++particle;
mParticleBuffer.pop_front();
continue;
}
vecAccel = particle->vecLocation-vecLocation;
vecAccel.Normalize();
vecAccel2 = vecAccel;
vecAccel *= particle->fRadialAccel;
// vecAccel2.Rotate(M_PI_2);
// the following is faster
ang = vecAccel2.x;
vecAccel2.x = -vecAccel2.y;
vecAccel2.y = ang;
vecAccel2 *= particle->fTangentialAccel;
particle->vecVelocity += (vecAccel+vecAccel2)*fDeltaTime;
particle->vecVelocity.y += particle->fGravity*fDeltaTime;
//par->vecVelocity.y = 0.1f;
particle->vecLocation += particle->vecVelocity;
particle->fSpin += particle->fSpinDelta*fDeltaTime;
particle->fSize += particle->fSizeDelta*fDeltaTime;
particle->colColor += particle->colColorDelta*fDeltaTime;
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(particle->vecLocation.x, particle->vecLocation.y);
++particle;
}
// generate new particles
if(fAge != -2.0f)
{
float fParticlesNeeded = info.nEmission*fDeltaTime + fEmissionResidue;
int nParticlesCreated = (unsigned int)fParticlesNeeded;
fEmissionResidue=fParticlesNeeded-nParticlesCreated;
for(i=0; i<nParticlesCreated; i++)
{
if(nParticlesAlive>=MAX_PARTICLES) break;
hgeParticle newParticle;
newParticle.fAge = 0.0f;
newParticle.fTerminalAge = Random_Float(info.fParticleLifeMin, info.fParticleLifeMax);
newParticle.vecLocation = vecPrevLocation+(vecLocation-vecPrevLocation)*Random_Float(0.0f, 1.0f);
newParticle.vecLocation.x += Random_Float(-2.0f, 2.0f);
newParticle.vecLocation.y += Random_Float(-2.0f, 2.0f);
ang=info.fDirection-M_PI_2+Random_Float(0,info.fSpread)-info.fSpread/2.0f;
if(info.bRelative) ang += (vecPrevLocation-vecLocation).Angle()+M_PI_2;
newParticle.vecVelocity.x = cosf(ang);
newParticle.vecVelocity.y = sinf(ang);
newParticle.vecVelocity *= Random_Float(info.fSpeedMin, info.fSpeedMax);
newParticle.fGravity = Random_Float(info.fGravityMin, info.fGravityMax);
newParticle.fRadialAccel = Random_Float(info.fRadialAccelMin, info.fRadialAccelMax);
newParticle.fTangentialAccel = Random_Float(info.fTangentialAccelMin, info.fTangentialAccelMax);
newParticle.fSize = Random_Float(info.fSizeStart, info.fSizeStart+(info.fSizeEnd-info.fSizeStart)*info.fSizeVar);
newParticle.fSizeDelta = (info.fSizeEnd-newParticle.fSize) / newParticle.fTerminalAge;
newParticle.fSpin = Random_Float(info.fSpinStart, info.fSpinStart+(info.fSpinEnd-info.fSpinStart)*info.fSpinVar);
newParticle.fSpinDelta = (info.fSpinEnd-newParticle.fSpin) / newParticle.fTerminalAge;
newParticle.colColor.r = Random_Float(info.colColorStart.r, info.colColorStart.r+(info.colColorEnd.r-info.colColorStart.r)*info.fColorVar);
newParticle.colColor.g = Random_Float(info.colColorStart.g, info.colColorStart.g+(info.colColorEnd.g-info.colColorStart.g)*info.fColorVar);
newParticle.colColor.b = Random_Float(info.colColorStart.b, info.colColorStart.b+(info.colColorEnd.b-info.colColorStart.b)*info.fColorVar);
newParticle.colColor.a = Random_Float(info.colColorStart.a, info.colColorStart.a+(info.colColorEnd.a-info.colColorStart.a)*info.fAlphaVar);
newParticle.colColorDelta.r = (info.colColorEnd.r-newParticle.colColor.r) / newParticle.fTerminalAge;
newParticle.colColorDelta.g = (info.colColorEnd.g-newParticle.colColor.g) / newParticle.fTerminalAge;
newParticle.colColorDelta.b = (info.colColorEnd.b-newParticle.colColor.b) / newParticle.fTerminalAge;
newParticle.colColorDelta.a = (info.colColorEnd.a-newParticle.colColor.a) / newParticle.fTerminalAge;
if(bUpdateBoundingBox) rectBoundingBox.Encapsulate(newParticle.vecLocation.x, newParticle.vecLocation.y);
mParticleBuffer.push_back(newParticle);
++nParticlesAlive;
}
}
vecPrevLocation=vecLocation;
}
void hgeParticleSystem::MoveTo(float x, float y, bool bMoveParticles)
{
float dx,dy;
if(bMoveParticles)
{
dx=x-vecLocation.x;
dy=y-vecLocation.y;
ParticleBuffer::iterator particle = mParticleBuffer.begin();
for (; particle != mParticleBuffer.end(); ++particle)
{
particle->vecLocation.x += dx;
particle->vecLocation.y += dy;
}
vecPrevLocation.x=vecPrevLocation.x + dx;
vecPrevLocation.y=vecPrevLocation.y + dy;
}
else
{
if(fAge==-2.0) { vecPrevLocation.x=x; vecPrevLocation.y=y; }
else { vecPrevLocation.x=vecLocation.x; vecPrevLocation.y=vecLocation.y; }
}
vecLocation.x=x;
vecLocation.y=y;
}
void hgeParticleSystem::FireAt(float x, float y)
{
Stop();
MoveTo(x,y);
Fire();
}
void hgeParticleSystem::Fire()
{
mTimer = 0.0f;
if(info.fLifetime==-1.0f) fAge=-1.0f;
else fAge=0.0f;
}
void hgeParticleSystem::Stop(bool bKillParticles)
{
fAge=-2.0f;
if(bKillParticles)
{
nParticlesAlive=0;
mParticleBuffer.clear();
rectBoundingBox.Clear();
}
}
void hgeParticleSystem::Render()
{
ParticleBuffer::iterator particle = mParticleBuffer.begin();
for (;particle != mParticleBuffer.end(); ++particle)
{
info.sprite->SetColor(particle->colColor.GetHWColor());
JRenderer::GetInstance()->RenderQuad(
info.sprite,
particle->vecLocation.x+fTx, particle->vecLocation.y+fTy,
particle->fSpin * particle->fAge,
particle->fSize, particle->fSize);
}
}
+91 -91
View File
@@ -1,91 +1,91 @@
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeParticleManager helper class implementation
*/
#include "../../include/hge/hgeparticle.h"
hgeParticleManager::hgeParticleManager()
{
nPS=0;
tX=tY=0.0f;
}
hgeParticleManager::~hgeParticleManager()
{
int i;
for(i=0;i<nPS;i++) delete psList[i];
}
void hgeParticleManager::Update(float dt)
{
int i;
for(i=0;i<nPS;i++)
{
psList[i]->Update(dt);
if(psList[i]->GetAge()==-2.0f && psList[i]->GetParticlesAlive()==0)
{
delete psList[i];
psList[i]=psList[nPS-1];
nPS--;
i--;
}
}
}
void hgeParticleManager::Render()
{
int i;
for(i=0;i<nPS;i++) psList[i]->Render();
}
hgeParticleSystem* hgeParticleManager::SpawnPS(hgeParticleSystemInfo *psi, float x, float y)
{
if(nPS==MAX_PSYSTEMS) return 0;
psList[nPS]=new hgeParticleSystem(psi);
psList[nPS]->FireAt(x,y);
psList[nPS]->Transpose(tX,tY);
nPS++;
return psList[nPS-1];
}
bool hgeParticleManager::IsPSAlive(hgeParticleSystem *ps) const
{
int i;
for(i=0;i<nPS;i++) if(psList[i]==ps) return true;
return false;
}
void hgeParticleManager::Transpose(float x, float y)
{
int i;
for(i=0;i<nPS;i++) psList[i]->Transpose(x,y);
tX=x; tY=y;
}
void hgeParticleManager::KillPS(hgeParticleSystem *ps)
{
int i;
for(i=0;i<nPS;i++)
{
if(psList[i]==ps)
{
delete psList[i];
psList[i]=psList[nPS-1];
nPS--;
return;
}
}
}
void hgeParticleManager::KillAll()
{
int i;
for(i=0;i<nPS;i++) delete psList[i];
nPS=0;
}
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeParticleManager helper class implementation
*/
#include "../../include/hge/hgeparticle.h"
hgeParticleManager::hgeParticleManager()
{
nPS=0;
tX=tY=0.0f;
}
hgeParticleManager::~hgeParticleManager()
{
int i;
for(i=0;i<nPS;i++) delete psList[i];
}
void hgeParticleManager::Update(float dt)
{
int i;
for(i=0;i<nPS;i++)
{
psList[i]->Update(dt);
if(psList[i]->GetAge()==-2.0f && psList[i]->GetParticlesAlive()==0)
{
delete psList[i];
psList[i]=psList[nPS-1];
nPS--;
i--;
}
}
}
void hgeParticleManager::Render()
{
int i;
for(i=0;i<nPS;i++) psList[i]->Render();
}
hgeParticleSystem* hgeParticleManager::SpawnPS(hgeParticleSystemInfo *psi, float x, float y)
{
if(nPS==MAX_PSYSTEMS) return 0;
psList[nPS]=new hgeParticleSystem(psi);
psList[nPS]->FireAt(x,y);
psList[nPS]->Transpose(tX,tY);
nPS++;
return psList[nPS-1];
}
bool hgeParticleManager::IsPSAlive(hgeParticleSystem *ps) const
{
int i;
for(i=0;i<nPS;i++) if(psList[i]==ps) return true;
return false;
}
void hgeParticleManager::Transpose(float x, float y)
{
int i;
for(i=0;i<nPS;i++) psList[i]->Transpose(x,y);
tX=x; tY=y;
}
void hgeParticleManager::KillPS(hgeParticleSystem *ps)
{
int i;
for(i=0;i<nPS;i++)
{
if(psList[i]==ps)
{
delete psList[i];
psList[i]=psList[nPS-1];
nPS--;
return;
}
}
}
void hgeParticleManager::KillAll()
{
int i;
for(i=0;i<nPS;i++) delete psList[i];
nPS=0;
}
+45 -45
View File
@@ -1,45 +1,45 @@
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeRect helper class implementation
*/
#include "../../include/hge/hgerect.h"
#include <math.h>
void hgeRect::Encapsulate(float x, float y)
{
if(bClean)
{
x1=x2=x;
y1=y2=y;
bClean=false;
}
else
{
if(x<x1) x1=x;
if(x>x2) x2=x;
if(y<y1) y1=y;
if(y>y2) y2=y;
}
}
bool hgeRect::TestPoint(float x, float y) const
{
if(x>=x1 && x<x2 && y>=y1 && y<y2) return true;
return false;
}
bool hgeRect::Intersect(const hgeRect *rect) const
{
if(fabs(x1 + x2 - rect->x1 - rect->x2) < (x2 - x1 + rect->x2 - rect->x1))
if(fabs(y1 + y2 - rect->y1 - rect->y2) < (y2 - y1 + rect->y2 - rect->y1))
return true;
return false;
}
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeRect helper class implementation
*/
#include "../../include/hge/hgerect.h"
#include <math.h>
void hgeRect::Encapsulate(float x, float y)
{
if(bClean)
{
x1=x2=x;
y1=y2=y;
bClean=false;
}
else
{
if(x<x1) x1=x;
if(x>x2) x2=x;
if(y<y1) y1=y;
if(y>y2) y2=y;
}
}
bool hgeRect::TestPoint(float x, float y) const
{
if(x>=x1 && x<x2 && y>=y1 && y<y2) return true;
return false;
}
bool hgeRect::Intersect(const hgeRect *rect) const
{
if(fabs(x1 + x2 - rect->x1 - rect->x2) < (x2 - x1 + rect->x2 - rect->x1))
if(fabs(y1 + y2 - rect->y1 - rect->y2) < (y2 - y1 + rect->y2 - rect->y1))
return true;
return false;
}
+69 -69
View File
@@ -1,69 +1,69 @@
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeVector helper class implementation
*/
#include "../../include/hge/hgevector.h"
float InvSqrt(float x)
{
union
{
int intPart;
float floatPart;
} convertor;
convertor.floatPart = x;
convertor.intPart = 0x5f3759df - (convertor.intPart >> 1);
return convertor.floatPart*(1.5f - 0.4999f*x*convertor.floatPart*convertor.floatPart);
}
/*
hgeVector *hgeVector::Normalize()
{
float lenRcp;
lenRcp=sqrtf(Dot(this));
if(lenRcp)
{
lenRcp=1.0f/lenRcp;
x*=lenRcp;
y*=lenRcp;
}
return this;
}
*/
float hgeVector::Angle(const hgeVector *v) const
{
if(v)
{
hgeVector s=*this, t=*v;
s.Normalize(); t.Normalize();
return acosf(s.Dot(&t));
}
else return atan2f(y, x);
}
hgeVector *hgeVector::Rotate(float a)
{
hgeVector v;
v.x=x*cosf(a) - y*sinf(a);
v.y=x*sinf(a) + y*cosf(a);
x=v.x; y=v.y;
return this;
}
/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** hgeVector helper class implementation
*/
#include "../../include/hge/hgevector.h"
float InvSqrt(float x)
{
union
{
int intPart;
float floatPart;
} convertor;
convertor.floatPart = x;
convertor.intPart = 0x5f3759df - (convertor.intPart >> 1);
return convertor.floatPart*(1.5f - 0.4999f*x*convertor.floatPart*convertor.floatPart);
}
/*
hgeVector *hgeVector::Normalize()
{
float lenRcp;
lenRcp=sqrtf(Dot(this));
if(lenRcp)
{
lenRcp=1.0f/lenRcp;
x*=lenRcp;
y*=lenRcp;
}
return this;
}
*/
float hgeVector::Angle(const hgeVector *v) const
{
if(v)
{
hgeVector s=*this, t=*v;
s.Normalize(); t.Normalize();
return acosf(s.Dot(&t));
}
else return atan2f(y, x);
}
hgeVector *hgeVector::Rotate(float a)
{
hgeVector v;
v.x=x*cosf(a) - y*sinf(a);
v.y=x*sinf(a) + y*cosf(a);
x=v.x; y=v.y;
return this;
}