#include "Game.h"
#include "Models.h"
-//#include "altivec.h"
extern float multiplier;
extern float viewdistance;
extern float fadestart;
extern float texdetail;
extern bool decals;
-extern int loadscreencolor;
-extern Game * pgame;
extern bool visibleloading;
-//Functions
-void *allocate_aligned(size_t pointer_size, size_t byte_alignment)
-{
- uintptr_t pointer = (uintptr_t)malloc(pointer_size + byte_alignment + 1);
- uintptr_t aligned_pointer = (pointer + byte_alignment + 1);
- aligned_pointer -= (aligned_pointer % byte_alignment);
- *(uint8_t *)(aligned_pointer - 1) = (aligned_pointer - pointer);
- return (void *)aligned_pointer;
-}
-
-void free_aligned(void *aligned_pointer)
-{
- free((uint8_t *)(aligned_pointer) - *((uint8_t *)(aligned_pointer) - 1));
-}
-
-void dealloc(void* param){
- free(param);
- param=0;
-}
int Model::LineCheck(XYZ *p1,XYZ *p2, XYZ *p, XYZ *move, float *rotate)
{
funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
// read the model data
- /*if(owner)dealloc(owner);
- if(possible)dealloc(possible);
- if(vertex)dealloc(vertex);
- if(normals)dealloc(normals);
- if(facenormals)dealloc(facenormals);
- if(Triangles)dealloc(Triangles);
- if(vArray)dealloc(vArray);*/
deallocate();
numpossible=0;
LOG(std::string("Loading model...") + filename);
- if(visibleloading){
- loadscreencolor=2;
- pgame->LoadingScreen();
- }
+ if(visibleloading)
+ Game::LoadingScreen();
int oldvertexNum,oldTriangleNum;
oldvertexNum=vertexNum;
funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
// read the model data
- /*if(owner)dealloc(owner);
- if(possible)dealloc(possible);
- if(vertex)dealloc(vertex);
- if(normals)dealloc(normals);
- if(facenormals)dealloc(facenormals);
- if(Triangles)dealloc(Triangles);
- if(vArray)dealloc(vArray);*/
deallocate();
numpossible=0;
funpackf(tfile, "Bf Bf Bf", &Triangles[i].gy[0], &Triangles[i].gy[1], &Triangles[i].gy[2]);
}
- Texture.xsz=0;
+ modelTexture.xsz=0;
fclose(tfile);
// read the model data
- /*if(owner)dealloc(owner);
- if(possible)dealloc(possible);
- if(vertex)dealloc(vertex);
- if(normals)dealloc(normals);
- if(facenormals)dealloc(facenormals);
- if(Triangles)dealloc(Triangles);
- if(vArray)dealloc(vArray);*/
deallocate();
numpossible=0;
}
- Texture.xsz=0;
+ modelTexture.xsz=0;
fclose(tfile);
funpackf(tfile, "Bs Bs", &vertexNum, &TriangleNum);
// read the model data
- /*if(owner)dealloc(owner);
- if(possible)dealloc(possible);
- if(vertex)dealloc(vertex);
- if(normals)dealloc(normals);
- if(facenormals)dealloc(facenormals);
- if(Triangles)dealloc(Triangles);
- if(vArray)dealloc(vArray);*/
deallocate();
numpossible=0;
void Model::CalculateNormals(bool facenormalise)
{
- if(visibleloading){
- loadscreencolor=3;
- pgame->LoadingScreen();
- }
+ if(visibleloading)
+ Game::LoadingScreen();
static int i;
if(type!=normaltype&&type!=decalstype)return;
void Model::drawimmediate()
{
- glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr);
+ textureptr.bind();
glBegin(GL_TRIANGLES);
for(int i=0;i<TriangleNum;i++){
/*if(Triangles[i].vertex[0]<vertexNum&&Triangles[i].vertex[1]<vertexNum&&Triangles[i].vertex[2]<vertexNum&&Triangles[i].vertex[0]>=0&&Triangles[i].vertex[1]>=0&&Triangles[i].vertex[2]>=0){
if(!color)glInterleavedArrays( GL_T2F_N3F_V3F,8*sizeof(GLfloat),&vArray[0]);
if(color)glInterleavedArrays( GL_T2F_C3F_V3F,8*sizeof(GLfloat),&vArray[0]);
- glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr);
+ textureptr.bind();
#if PLATFORM_MACOSX
glLockArraysEXT( 0, TriangleNum*3);
//drawimmediate();
}
+//TODO: phase out in favor of Texture
void Model::drawdifftex(GLuint texture)
{
glEnableClientState(GL_NORMAL_ARRAY);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
+#ifndef WIN32
+ glLockArraysEXT( 0, TriangleNum*3);
+#endif
+ glDrawArrays(GL_TRIANGLES, 0, TriangleNum*3);
+#ifndef WIN32
+ glUnlockArraysEXT();
+#endif
+
+
+ if(!color)glDisableClientState(GL_NORMAL_ARRAY);
+ if(color)glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ //drawdiffteximmediate(texture);
+}
+
+void Model::drawdifftex(Texture texture)
+{
+ glEnableClientState(GL_NORMAL_ARRAY);
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ if(!color)glInterleavedArrays( GL_T2F_N3F_V3F,8*sizeof(GLfloat),&vArray[0]);
+ if(color)glInterleavedArrays( GL_T2F_C3F_V3F,8*sizeof(GLfloat),&vArray[0]);
+
+ texture.bind();
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
+ glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
+
+
#ifndef WIN32
glLockArraysEXT( 0, TriangleNum*3);
#endif
glEnd();
}
-void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtexture2,GLuint breaktexture)
+void Model::drawdecals(Texture shadowtexture,Texture bloodtexture,Texture bloodtexture2,Texture breaktexture)
{
if(decals){
if(type!=decalstype)return;
if(decaltype[i]==blooddecalfast&&decalalivetime[i]<2)decalalivetime[i]=2;
if(decaltype[i]==shadowdecal&&decaltype[i]!=lasttype){
- glBindTexture( GL_TEXTURE_2D, shadowtexture);
+ shadowtexture.bind();
if(!blend){
blend=1;
glAlphaFunc(GL_GREATER, 0.0001);
}
}
if(decaltype[i]==breakdecal&&decaltype[i]!=lasttype){
- glBindTexture( GL_TEXTURE_2D, breaktexture);
+ breaktexture.bind();
if(!blend){
blend=1;
glAlphaFunc(GL_GREATER, 0.0001);
}
}
if((decaltype[i]==blooddecal||decaltype[i]==blooddecalslow)&&decaltype[i]!=lasttype){
- glBindTexture( GL_TEXTURE_2D, bloodtexture);
+ bloodtexture.bind();
if(blend){
blend=0;
glAlphaFunc(GL_GREATER, 0.15);
}
}
if((decaltype[i]==blooddecalfast)&&decaltype[i]!=lasttype){
- glBindTexture( GL_TEXTURE_2D, bloodtexture2);
+ bloodtexture2.bind();
if(blend){
blend=0;
glAlphaFunc(GL_GREATER, 0.15);
Model::~Model()
{
deallocate();
-
- if(textureptr) glDeleteTextures( 1, &textureptr );
+ textureptr.destroy();
}
void Model::deallocate()
{
int i = 0, j = 0;
- if(owner)dealloc(owner);
+ if(owner)free(owner);
owner = 0;
- if(possible)dealloc(possible);
+ if(possible)free(possible);
possible = 0;
- if(vertex)dealloc(vertex);
+ if(vertex)free(vertex);
vertex = 0;
- if(normals)dealloc(normals);
+ if(normals)free(normals);
normals = 0;
- if(facenormals)dealloc(facenormals);
+ if(facenormals)free(facenormals);
facenormals = 0;
- if(Triangles)dealloc(Triangles);
+ if(Triangles)free(Triangles);
Triangles = 0;
- if(vArray)dealloc(vArray);
+ if(vArray)free(vArray);
vArray = 0;
{
for(j=0;j<3;j++)
{
- dealloc(decaltexcoords[i][j]);
+ free(decaltexcoords[i][j]);
}
- dealloc(decaltexcoords[i]);
+ free(decaltexcoords[i]);
}
- dealloc(decaltexcoords);
+ free(decaltexcoords);
}
decaltexcoords = 0;
{
for(i=0;i<max_model_decals;i++)
{
- dealloc(decalvertex[i]);
+ free(decalvertex[i]);
}
- dealloc(decalvertex);
+ free(decalvertex);
}
decalvertex = 0;
- dealloc(decaltype);
+ free(decaltype);
decaltype = 0;
- dealloc(decalopacity);
+ free(decalopacity);
decalopacity = 0;
- dealloc(decalrotation);
+ free(decalrotation);
decalrotation = 0;
- dealloc(decalalivetime);
+ free(decalalivetime);
decalalivetime = 0;
- dealloc(decalposition);
+ free(decalposition);
decalposition = 0;
};
Triangles=0;
vArray=0;
- textureptr = 0;
- memset(&Texture, 0, sizeof(Texture));
+ memset(&modelTexture, 0, sizeof(modelTexture));
numpossible = 0;
color = 0;