Skip to content

Commit

Permalink
<ivis_opengl>
Browse files Browse the repository at this point in the history
astyle with:
--suffix=none
--style=allman
--indent=tab
--indent-cases
--indent-namespaces
--pad-oper
--pad-header
--unpad-paren
--add-brackets
--align-pointer=name
--min-conditional-indent=0
--indent-preprocessor
--keep-one-line-statements
  • Loading branch information
vexed committed Mar 16, 2015
1 parent 7ba8876 commit 97f2e86
Show file tree
Hide file tree
Showing 30 changed files with 671 additions and 561 deletions.
32 changes: 19 additions & 13 deletions lib/ivis_opengl/bitimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ struct ImageMergeRectangle
{
bool operator <(ImageMergeRectangle const &b) const
{
if (std::max(siz.x, siz.y) != std::max(b.siz.x, b.siz.y)) return std::max(siz.x, siz.y) < std::max(b.siz.x, b.siz.y);
if (std::min(siz.x, siz.y) != std::min(b.siz.x, b.siz.y)) return std::min(siz.x, siz.y) < std::min(b.siz.x, b.siz.y);
return siz.x < b.siz.x;
if (std::max(siz.x, siz.y) != std::max(b.siz.x, b.siz.y))
{
return std::max(siz.x, siz.y) < std::max(b.siz.x, b.siz.y);
}
if (std::min(siz.x, siz.y) != std::min(b.siz.x, b.siz.y))
{
return std::min(siz.x, siz.y) < std::min(b.siz.x, b.siz.y);
}
return siz.x < b.siz.x;
}

int index; // Index in ImageDefs array.
Expand Down Expand Up @@ -193,8 +199,8 @@ IMAGEFILE *iV_LoadImageFile(const char *fileName)
ivImages[p].depth = 4;
ivImages[p].width = size;
ivImages[p].height = size;
ivImages[p].bmp = (unsigned char *)malloc(size*size*4); // MUST be malloc, since this is free()d later by pie_AddTexPage().
memset(ivImages[p].bmp, 0x00, size*size*4);
ivImages[p].bmp = (unsigned char *)malloc(size * size * 4); // MUST be malloc, since this is free()d later by pie_AddTexPage().
memset(ivImages[p].bmp, 0x00, size * size * 4);
imageFile->pages[p].size = size;
// Must set imageFile->pages[p].id later, after filling out ivImages[p].bmp.
}
Expand All @@ -210,20 +216,20 @@ IMAGEFILE *iV_LoadImageFile(const char *fileName)
// Copy image data onto texture page.
iV_Image *srcImage = r->data;
int srcDepth = srcImage->depth;
int srcStride = srcImage->width*srcDepth; // Not sure whether to pad in the case that srcDepth ≠ 4, however this apparently cannot happen.
unsigned char *srcBytes = srcImage->bmp + 0*srcDepth + 0*srcStride;
int srcStride = srcImage->width * srcDepth; // Not sure whether to pad in the case that srcDepth ≠ 4, however this apparently cannot happen.
unsigned char *srcBytes = srcImage->bmp + 0 * srcDepth + 0 * srcStride;
iV_Image *dstImage = &ivImages[r->page];
int dstDepth = dstImage->depth;
int dstStride = dstImage->width*dstDepth;
unsigned char *dstBytes = dstImage->bmp + r->loc.x*dstDepth + r->loc.y*dstStride;
int dstStride = dstImage->width * dstDepth;
unsigned char *dstBytes = dstImage->bmp + r->loc.x * dstDepth + r->loc.y * dstStride;
Vector2i size = r->siz;
unsigned char rgba[4] = {0x00, 0x00, 0x00, 0xFF};
for (int y = 0; y < size.y; ++y)
for (int x = 0; x < size.x; ++x)
{
memcpy(rgba, srcBytes + x*srcDepth + y*srcStride, srcDepth);
memcpy(dstBytes + x*dstDepth + y*dstStride, rgba, dstDepth);
}
{
memcpy(rgba, srcBytes + x * srcDepth + y * srcStride, srcDepth);
memcpy(dstBytes + x * dstDepth + y * dstStride, rgba, dstDepth);
}

// Finished reading the image data and copying it to the texture page, delete it.
free(r->data->bmp);
Expand Down
4 changes: 2 additions & 2 deletions lib/ivis_opengl/bitimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ static inline WZ_DECL_PURE short iV_GetImageYOffset(const IMAGEFILE *ImageFile,
static inline WZ_DECL_PURE unsigned short iV_GetImageCenterX(const IMAGEFILE *ImageFile, const unsigned short ID)
{
assert(ID < ImageFile->imageDefs.size());
return ImageFile->imageDefs[ID].XOffset + ImageFile->imageDefs[ID].Width/2;
return ImageFile->imageDefs[ID].XOffset + ImageFile->imageDefs[ID].Width / 2;
}


static inline WZ_DECL_PURE unsigned short iV_GetImageCenterY(const IMAGEFILE *ImageFile, const unsigned short ID)
{
assert(ID < ImageFile->imageDefs.size());
return ImageFile->imageDefs[ID].YOffset + ImageFile->imageDefs[ID].Height/2;
return ImageFile->imageDefs[ID].YOffset + ImageFile->imageDefs[ID].Height / 2;
}


Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/imd.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

//*************************************************************************

extern iIMDShape *iV_ProcessIMD(const char **ppFileData, const char *FileDataEnd );
extern iIMDShape *iV_ProcessIMD(const char **ppFileData, const char *FileDataEnd);

extern bool iV_IMDSave(char *filename, iIMDShape *s, bool PieIMD);
extern void iV_IMDRelease(iIMDShape *s);
Expand Down
72 changes: 36 additions & 36 deletions lib/ivis_opengl/imdload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

static bool AtEndOfFile(const char *CurPos, const char *EndOfFile)
{
while ( *CurPos == 0x00 || *CurPos == 0x09 || *CurPos == 0x0a || *CurPos == 0x0d || *CurPos == 0x20 )
while (*CurPos == 0x00 || *CurPos == 0x09 || *CurPos == 0x0a || *CurPos == 0x0d || *CurPos == 0x20)
{
CurPos++;
if (CurPos >= EndOfFile)
Expand Down Expand Up @@ -64,7 +64,7 @@ static bool AtEndOfFile(const char *CurPos, const char *EndOfFile)
* \post s->polys allocated (iFSDPoly * s->npolys)
* \post s->pindex allocated for each poly
*/
static bool _imd_load_polys( const char **ppFileData, iIMDShape *s, int pieVersion)
static bool _imd_load_polys(const char **ppFileData, iIMDShape *s, int pieVersion)
{
const char *pFileData = *ppFileData;
unsigned int i, j;
Expand All @@ -73,7 +73,7 @@ static bool _imd_load_polys( const char **ppFileData, iIMDShape *s, int pieVersi
s->numFrames = 0;
s->animInterval = 0;

s->polys = (iIMDPoly*)malloc(sizeof(iIMDPoly) * s->npolys);
s->polys = (iIMDPoly *)malloc(sizeof(iIMDPoly) * s->npolys);
if (s->polys == NULL)
{
debug(LOG_ERROR, "(_load_polys) Out of memory (polys)");
Expand Down Expand Up @@ -114,9 +114,9 @@ static bool _imd_load_polys( const char **ppFileData, iIMDShape *s, int pieVersi
p1.y = s->points[poly->pindex[1]].y;
p1.z = s->points[poly->pindex[1]].z;

p2.x = s->points[poly->pindex[poly->npnts-1]].x;
p2.y = s->points[poly->pindex[poly->npnts-1]].y;
p2.z = s->points[poly->pindex[poly->npnts-1]].z;
p2.x = s->points[poly->pindex[poly->npnts - 1]].x;
p2.y = s->points[poly->pindex[poly->npnts - 1]].y;
p2.z = s->points[poly->pindex[poly->npnts - 1]].z;

poly->normal = pie_SurfaceNormal3fv(p0, p1, p2);
}
Expand Down Expand Up @@ -150,11 +150,11 @@ static bool _imd_load_polys( const char **ppFileData, iIMDShape *s, int pieVersi
else
{
ASSERT(s->numFrames == nFrames,
"%s: varying number of frames within one PIE level: %d != %d",
GetLastResourceFilename(), nFrames, s->numFrames);
"%s: varying number of frames within one PIE level: %d != %d",
GetLastResourceFilename(), nFrames, s->numFrames);
ASSERT(s->animInterval == pbRate,
"%s: varying animation intervals within one PIE level: %d != %d",
GetLastResourceFilename(), pbRate, s->animInterval);
"%s: varying animation intervals within one PIE level: %d != %d",
GetLastResourceFilename(), pbRate, s->animInterval);
}

poly->texAnim.x = tWidth;
Expand All @@ -165,7 +165,7 @@ static bool _imd_load_polys( const char **ppFileData, iIMDShape *s, int pieVersi
poly->texAnim.x /= OLD_TEXTURE_SIZE_FIX;
poly->texAnim.y /= OLD_TEXTURE_SIZE_FIX;
}
framesPerLine = 1/poly->texAnim.x;
framesPerLine = 1 / poly->texAnim.x;
}
else
{
Expand Down Expand Up @@ -221,7 +221,7 @@ static bool _imd_load_polys( const char **ppFileData, iIMDShape *s, int pieVersi
}


static bool ReadPoints( const char **ppFileData, iIMDShape *s )
static bool ReadPoints(const char **ppFileData, iIMDShape *s)
{
const char *pFileData = *ppFileData;
unsigned int i;
Expand All @@ -243,7 +243,7 @@ static bool ReadPoints( const char **ppFileData, iIMDShape *s )
}


static bool _imd_load_points( const char **ppFileData, iIMDShape *s )
static bool _imd_load_points(const char **ppFileData, iIMDShape *s)
{
Vector3f *p = NULL;
int32_t xmax, ymax, zmax;
Expand All @@ -254,14 +254,14 @@ static bool _imd_load_points( const char **ppFileData, iIMDShape *s )
vxmax(0, 0, 0), vymax(0, 0, 0), vzmax(0, 0, 0);

//load the points then pass through a second time to setup bounding datavalues
s->points = (Vector3f*)malloc(sizeof(Vector3f) * s->npoints);
s->points = (Vector3f *)malloc(sizeof(Vector3f) * s->npoints);
if (s->points == NULL)
{
return false;
}

// Read in points and remove duplicates (!)
if ( ReadPoints( ppFileData, s ) == false )
if (ReadPoints(ppFileData, s) == false)
{
free(s->points);
s->points = NULL;
Expand Down Expand Up @@ -354,27 +354,27 @@ static bool _imd_load_points( const char **ppFileData, iIMDShape *s )
zmax = MAX(s->max.z, -s->min.z);

s->radius = MAX(xmax, MAX(ymax, zmax));
s->sradius = sqrtf(xmax*xmax + ymax*ymax + zmax*zmax);
s->sradius = sqrtf(xmax * xmax + ymax * ymax + zmax * zmax);

// START: tight bounding sphere

// set xspan = distance between 2 points xmin & xmax (squared)
dx = vxmax.x - vxmin.x;
dy = vxmax.y - vxmin.y;
dz = vxmax.z - vxmin.z;
xspan = dx*dx + dy*dy + dz*dz;
xspan = dx * dx + dy * dy + dz * dz;

// same for yspan
dx = vymax.x - vymin.x;
dy = vymax.y - vymin.y;
dz = vymax.z - vymin.z;
yspan = dx*dx + dy*dy + dz*dz;
yspan = dx * dx + dy * dy + dz * dz;

// and ofcourse zspan
dx = vzmax.x - vzmin.x;
dy = vzmax.y - vzmin.y;
dz = vzmax.z - vzmin.z;
zspan = dx*dx + dy*dy + dz*dz;
zspan = dx * dx + dy * dy + dz * dz;

// set points dia1 & dia2 to maximally seperated pair
// assume xspan biggest
Expand Down Expand Up @@ -405,7 +405,7 @@ static bool _imd_load_points( const char **ppFileData, iIMDShape *s )
dy = dia2.y - cen.y;
dz = dia2.z - cen.z;

rad_sq = dx*dx + dy*dy + dz*dz;
rad_sq = dx * dx + dy * dy + dz * dz;
rad = sqrt((double)rad_sq);

// second pass (find tight sphere)
Expand All @@ -414,22 +414,22 @@ static bool _imd_load_points( const char **ppFileData, iIMDShape *s )
dx = p->x - cen.x;
dy = p->y - cen.y;
dz = p->z - cen.z;
old_to_p_sq = dx*dx + dy*dy + dz*dz;
old_to_p_sq = dx * dx + dy * dy + dz * dz;

// do r**2 first
if (old_to_p_sq>rad_sq)
if (old_to_p_sq > rad_sq)
{
// this point outside current sphere
old_to_p = sqrt((double)old_to_p_sq);
// radius of new sphere
rad = (rad + old_to_p) / 2.;
// rad**2 for next compare
rad_sq = rad*rad;
rad_sq = rad * rad;
old_to_new = old_to_p - rad;
// centre of new sphere
cen.x = (rad*cen.x + old_to_new*p->x) / old_to_p;
cen.y = (rad*cen.y + old_to_new*p->y) / old_to_p;
cen.z = (rad*cen.z + old_to_new*p->z) / old_to_p;
cen.x = (rad * cen.x + old_to_new * p->x) / old_to_p;
cen.y = (rad * cen.y + old_to_new * p->y) / old_to_p;
cen.z = (rad * cen.z + old_to_new * p->z) / old_to_p;
}
}

Expand Down Expand Up @@ -508,7 +508,7 @@ static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataE
i = sscanf(pFileData, "%255s %n", buffer, &cnt);
ASSERT_OR_RETURN(NULL, i == 1, "Bad directive following LEVEL");

s = (iIMDShape*)malloc(sizeof(iIMDShape));
s = (iIMDShape *)malloc(sizeof(iIMDShape));
if (s == NULL)
{
/* Failed to allocate memory for s */
Expand Down Expand Up @@ -537,7 +537,7 @@ static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataE
i = sscanf(pFileData, "%255s %f %f %f %f %f %f %f %f %f %f%n", buffer,
&s->material[LIGHT_AMBIENT][0], &s->material[LIGHT_AMBIENT][1], &s->material[LIGHT_AMBIENT][2],
&s->material[LIGHT_DIFFUSE][0], &s->material[LIGHT_DIFFUSE][1], &s->material[LIGHT_DIFFUSE][2],
&s->material[LIGHT_SPECULAR][0], &s->material[LIGHT_SPECULAR][1], &s->material[LIGHT_SPECULAR][2],
&s->material[LIGHT_SPECULAR][0], &s->material[LIGHT_SPECULAR][1], &s->material[LIGHT_SPECULAR][2],
&s->shininess, &cnt);
ASSERT_OR_RETURN(NULL, i == 11, "Bad MATERIALS directive");
pFileData += cnt;
Expand Down Expand Up @@ -569,7 +569,7 @@ static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataE

ASSERT_OR_RETURN(NULL, strcmp(buffer, "POINTS") == 0, "Expecting 'POINTS' directive, got: %s", buffer);

_imd_load_points( &pFileData, s );
_imd_load_points(&pFileData, s);

if (sscanf(pFileData, "%255s %d%n", buffer, &s->npolys, &cnt) != 2)
{
Expand All @@ -580,7 +580,7 @@ static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataE

ASSERT_OR_RETURN(NULL, strcmp(buffer, "POLYGONS") == 0, "Expecting 'POLYGONS' directive, got: %s", buffer);

_imd_load_polys( &pFileData, s, pieVersion);
_imd_load_polys(&pFileData, s, pieVersion);


// NOW load optional stuff
Expand All @@ -604,7 +604,7 @@ static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataE
{
//load connector stuff
s->nconnectors = n;
_imd_load_connectors( &pFileData, s );
_imd_load_connectors(&pFileData, s);
}
else
{
Expand All @@ -626,7 +626,7 @@ static iIMDShape *_imd_load_level(const char **ppFileData, const char *FileDataE
* \return The shape, constructed from the data read
*/
// ppFileData is incremented to the end of the file on exit!
iIMDShape *iV_ProcessIMD( const char **ppFileData, const char *FileDataEnd )
iIMDShape *iV_ProcessIMD(const char **ppFileData, const char *FileDataEnd)
{
const char *pFileName = GetLastResourceFilename(); // Last loaded texture page filename
const char *pFileData = *ppFileData;
Expand Down Expand Up @@ -688,9 +688,9 @@ iIMDShape *iV_ProcessIMD( const char **ppFileData, const char *FileDataEnd )
ch = *pFileData++;

// Run up to the dot or till the buffer is filled. Leave room for the extension.
for (i = 0; i < PATH_MAX-5 && (ch = *pFileData++) != '\0' && ch != '.'; ++i)
for (i = 0; i < PATH_MAX - 5 && (ch = *pFileData++) != '\0' && ch != '.'; ++i)
{
texfile[i] = ch;
texfile[i] = ch;
}
texfile[i] = '\0';

Expand Down Expand Up @@ -736,9 +736,9 @@ iIMDShape *iV_ProcessIMD( const char **ppFileData, const char *FileDataEnd )
ch = *pFileData++;

// Run up to the dot or till the buffer is filled. Leave room for the extension.
for (i = 0; i < PATH_MAX-5 && (ch = *pFileData++) != '\0' && ch != '.'; ++i)
for (i = 0; i < PATH_MAX - 5 && (ch = *pFileData++) != '\0' && ch != '.'; ++i)
{
normalfile[i] = ch;
normalfile[i] = ch;
}
normalfile[i] = '\0';

Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/ivisdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct iIMDPoly

struct iIMDShape
{
unsigned int flags;
unsigned int flags;
int texpage;
int tcmaskpage;
int normalpage;
Expand Down
Loading

0 comments on commit 97f2e86

Please sign in to comment.