X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FSkeleton.cpp;h=878bcbe13511cc6ec54d317c146abe447246c94a;hb=8265984dce72d262e3865ebad4668d98b5b26d4a;hp=13366888df63f9d837d72c9cf89df4c51fbcfaa6;hpb=9472ba88471ee8b0aabea90ea11f428a87a81921;p=lugaru.git diff --git a/Source/Skeleton.cpp b/Source/Skeleton.cpp index 1336688..878bcbe 100644 --- a/Source/Skeleton.cpp +++ b/Source/Skeleton.cpp @@ -1,14 +1,36 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + /**> HEADER FILES <**/ +#include "Game.h" #include "Skeleton.h" +#include "openal_wrapper.h" extern float multiplier; extern float gravity; extern Skeleton testskeleton; extern Terrain terrain; -extern FSOUND_SAMPLE *samp[100]; +extern OPENAL_SAMPLE *samp[100]; extern int channels[100]; extern Objects objects; -extern Sprites sprites; extern int environment; extern float terraindetail; extern float camerashake; @@ -25,10 +47,9 @@ extern int tutoriallevel; extern int whichjointstartarray[26]; extern int whichjointendarray[26]; -#include "Game.h" extern Game * pgame; extern bool visibleloading; -extern "C" void PlaySoundEx(int channel, FSOUND_SAMPLE *sptr, FSOUND_DSPUNIT *dsp, signed char startpaused); +extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); void dealloc2(void* param){ free(param); @@ -182,7 +203,7 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) objects.SphereCheckPossible(&terrainlight, 1); /* for(i=0; i4000&&breaking){ objects.model[k].MakeDecal(breakdecal,DoRotation(temp-objects.position[k],0,-objects.rotation[k],0),.4,.5,Random()%360); - sprites.MakeSprite(cloudsprite, headpos*(*scale)+*coords,joints[jointlabels[head]].velocity*.06, 1,1,1, 4, .2); + Sprite::MakeSprite(cloudsprite, headpos*(*scale)+*coords,joints[jointlabels[head]].velocity*.06, 1,1,1, 4, .2); breaking=0; camerashake+=.6; @@ -319,10 +340,10 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) vel[0]=joints[jointlabels[head]].velocity.x; vel[1]=joints[jointlabels[head]].velocity.y; vel[2]=joints[jointlabels[head]].velocity.z; - PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE); - FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel); - FSOUND_SetVolume(channels[breaksound2], 300); - FSOUND_SetPaused(channels[breaksound2], FALSE); + PlaySoundEx( breaksound2, samp[breaksound2], NULL, true); + OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel); + OPENAL_SetVolume(channels[breaksound2], 300); + OPENAL_SetPaused(channels[breaksound2], false); envsound[numenvsounds]=*coords; envsoundvol[numenvsounds]=64; @@ -353,7 +374,7 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) joints[jointlabels[head]].locked=1; //joints[jointlabels[head]].velocity*=3; } - if(findLengthfast(&bounceness)>500)sprites.MakeSprite(cloudsprite, headpos*(*scale)+*coords,joints[jointlabels[head]].velocity*.06, 1,1,1, .5, .2); + if(findLengthfast(&bounceness)>500)Sprite::MakeSprite(cloudsprite, headpos*(*scale)+*coords,joints[jointlabels[head]].velocity*.06, 1,1,1, .5, .2); joints[jointlabels[head]].position=(temp-*coords)/(*scale)+(startheadpos-headpos)+terrainnormal*.005; if(longdead>100)broken=1; } @@ -404,10 +425,10 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) vel[1]=joints[i].velocity.y; vel[2]=joints[i].velocity.z; if(tutoriallevel!=1||id==0){ - PlaySoundEx( landsound1, samp[landsound1], NULL, TRUE); - FSOUND_3D_SetAttributes(channels[landsound1], gLoc, vel); - FSOUND_SetVolume(channels[landsound1], 128); - FSOUND_SetPaused(channels[landsound1], FALSE); + PlaySoundEx( landsound1, samp[landsound1], NULL, true); + OPENAL_3D_SetAttributes(channels[landsound1], gLoc, vel); + OPENAL_SetVolume(channels[landsound1], 128); + OPENAL_SetPaused(channels[landsound1], false); } breaking=1; } @@ -424,10 +445,10 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) vel[1]=joints[i].velocity.y; vel[2]=joints[i].velocity.z; if(tutoriallevel!=1||id==0){ - PlaySoundEx( landsound2, samp[landsound2], NULL, TRUE); - FSOUND_3D_SetAttributes(channels[landsound2], gLoc, vel); - FSOUND_SetVolume(channels[landsound2], 128); - FSOUND_SetPaused(channels[landsound2], FALSE); + PlaySoundEx( landsound2, samp[landsound2], NULL, true); + OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel); + OPENAL_SetVolume(channels[landsound2], 128); + OPENAL_SetPaused(channels[landsound2], false); } } @@ -444,8 +465,8 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) if(tutoriallevel!=1||id==0) if(findLengthfast(&bounceness)>8000&&breaking){ objects.model[k].MakeDecal(breakdecal,DoRotation(temp-objects.position[k],0,-objects.rotation[k],0),.4,.5,Random()%360); - sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 4, .2); - //sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 1, .2); + Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 4, .2); + //Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 1, .2); breaking=0; camerashake+=.6; @@ -457,10 +478,10 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) vel[0]=joints[i].velocity.x; vel[1]=joints[i].velocity.y; vel[2]=joints[i].velocity.z; - PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE); - FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel); - FSOUND_SetVolume(channels[breaksound2], 300); - FSOUND_SetPaused(channels[breaksound2], FALSE); + PlaySoundEx( breaksound2, samp[breaksound2], NULL, true); + OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel); + OPENAL_SetVolume(channels[breaksound2], 300); + OPENAL_SetPaused(channels[breaksound2], false); envsound[numenvsounds]=*coords; envsoundvol[numenvsounds]=64; @@ -471,7 +492,7 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) if(findLengthfast(&bounceness)>2500){ Normalise(&bounceness); bounceness=bounceness*50; - } + } joints[i].velocity+=bounceness*elasticity; @@ -486,19 +507,19 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) if(environment==snowyenvironment&&findLengthfast(&bounceness)>500&&terrain.getOpacity(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z)<.2){ terrainlight=terrain.getLighting(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z); - sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7); + Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7); if(detail==2)terrain.MakeDecal(bodyprintdecal, joints[i].position*(*scale)+*coords,.4,.4,0); } else if(environment==desertenvironment&&findLengthfast(&bounceness)>500&&terrain.getOpacity(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z)<.2){ terrainlight=terrain.getLighting(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z); - sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7); + Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7); } else if(environment==grassyenvironment&&findLengthfast(&bounceness)>500&&terrain.getOpacity(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z)<.2){ terrainlight=terrain.getLighting(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z); - sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5); + Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5); } - else if(findLengthfast(&bounceness)>500)sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x,terrainlight.y,terrainlight.z, .5, .2); + else if(findLengthfast(&bounceness)>500)Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, terrainlight.x,terrainlight.y,terrainlight.z, .5, .2); joints[i].position.y=(terrain.getHeight(joints[i].position.x*(*scale)+coords->x,joints[i].position.z*(*scale)+coords->z)+groundlevel-coords->y)/(*scale); @@ -526,10 +547,10 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) vel[1]=joints[i].velocity.y; vel[2]=joints[i].velocity.z; if(tutoriallevel!=1||id==0){ - PlaySoundEx( landsound1, samp[landsound1], NULL, TRUE); - FSOUND_3D_SetAttributes(channels[landsound1], gLoc, vel); - FSOUND_SetVolume(channels[landsound1], 128); - FSOUND_SetPaused(channels[landsound1], FALSE); + PlaySoundEx( landsound1, samp[landsound1], NULL, true); + OPENAL_3D_SetAttributes(channels[landsound1], gLoc, vel); + OPENAL_SetVolume(channels[landsound1], 128); + OPENAL_SetPaused(channels[landsound1], false); } breaking=1; } @@ -546,10 +567,10 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) vel[1]=joints[i].velocity.y; vel[2]=joints[i].velocity.z; if(tutoriallevel!=1||id==0){ - PlaySoundEx( landsound2, samp[landsound2], NULL, TRUE); - FSOUND_3D_SetAttributes(channels[landsound2], gLoc, vel); - FSOUND_SetVolume(channels[landsound2], 128); - FSOUND_SetPaused(channels[landsound2], FALSE); + PlaySoundEx( landsound2, samp[landsound2], NULL, true); + OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel); + OPENAL_SetVolume(channels[landsound2], 128); + OPENAL_SetPaused(channels[landsound2], false); } } @@ -563,7 +584,7 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) if(tutoriallevel!=1||id==0) if(findLengthfast(&bounceness)>4000&&breaking){ objects.model[k].MakeDecal(breakdecal,DoRotation(temp-objects.position[k],0,-objects.rotation[k],0),.4,.5,Random()%360); - sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 4, .2); + Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, 4, .2); breaking=0; camerashake+=.6; @@ -575,10 +596,10 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) vel[0]=joints[i].velocity.x; vel[1]=joints[i].velocity.y; vel[2]=joints[i].velocity.z; - PlaySoundEx( breaksound2, samp[breaksound2], NULL, TRUE); - FSOUND_3D_SetAttributes(channels[breaksound2], gLoc, vel); - FSOUND_SetVolume(channels[breaksound2], 300); - FSOUND_SetPaused(channels[breaksound2], FALSE); + PlaySoundEx( breaksound2, samp[breaksound2], NULL, true); + OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel); + OPENAL_SetVolume(channels[breaksound2], 300); + OPENAL_SetPaused(channels[breaksound2], false); envsound[numenvsounds]=*coords; envsoundvol[numenvsounds]=64; @@ -602,8 +623,8 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) pos.x+=float(abs(Random()%100)-50)/100*objects.scale[k]*5; pos.y+=float(abs(Random()%100)-50)/100*objects.scale[k]*15; pos.z+=float(abs(Random()%100)-50)/100*objects.scale[k]*5; - sprites.MakeSprite(splintersprite, pos,tempvel*.5, 165/255+float(abs(Random()%100)-50)/400,0,0, .2+float(abs(Random()%100)-50)/1300, 1); - sprites.special[sprites.numsprites-1]=1; + Sprite::MakeSprite(splintersprite, pos,tempvel*.5, 165/255+float(abs(Random()%100)-50)/400,0,0, .2+float(abs(Random()%100)-50)/1300, 1); + Sprite::special[Sprite::numsprites-1]=1; }*/ objects.rotx[k]+=joints[i].velocity.x*multiplier*.4; objects.roty[k]+=joints[i].velocity.z*multiplier*.4; @@ -628,7 +649,7 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) joints[i].locked=1; //joints[i].velocity*=3; } - if(findLengthfast(&bounceness)>500)sprites.MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, .5, .2); + if(findLengthfast(&bounceness)>500)Sprite::MakeSprite(cloudsprite, joints[i].position*(*scale)+*coords,joints[i].velocity*.06, 1,1,1, .5, .2); joints[i].position=(temp-*coords)/(*scale)+terrainnormal*.005; if(longdead>100)broken=1; } @@ -662,9 +683,9 @@ float Skeleton::DoConstraints(XYZ *coords,float *scale) for(i=0; iposition.x,muscles[i].parent1->position.y,muscles[i].parent1->position.z); glVertex3f(muscles[i].parent2->position.x,muscles[i].parent2->position.y,muscles[i].parent2->position.z); } - } + } glEnd(); if(muscleview!=2){ @@ -885,7 +906,7 @@ void Skeleton::SetJoint(float x, float y, float z, int which, int whichjoint) joints[whichjoint].parent=&joints[which]; joints[whichjoint].hasparent=1; joints[whichjoint].length=findDistance(&joints[whichjoint].position,&joints[whichjoint].parent->position); - } + } } } @@ -995,7 +1016,10 @@ void Animation::Load(char *filename, int aheight, int aattack) LOGFUNC; - LOG(std::string("Loading animation...") + filename); + // Changing the filename into something the OS can understand + char *fixedFN = ConvertFileName(filename); + + LOG(std::string("Loading animation...") + fixedFN); deallocate(); @@ -1004,7 +1028,7 @@ void Animation::Load(char *filename, int aheight, int aattack) if(visibleloading)pgame->LoadingScreen(); - tfile=fopen( filename, "rb" ); + tfile=fopen( fixedFN, "rb" ); if(tfile){ funpackf(tfile, "Bi Bi", &numframes, &joints); /* @@ -1081,7 +1105,7 @@ void Animation::Load(char *filename, int aheight, int aattack) funpackf(tfile, "Bf Bf Bf", &weapontarget[i].x,&weapontarget[i].y,&weapontarget[i].z); } - fclose(tfile); + fclose(tfile); } startoffset=0; @@ -1111,7 +1135,12 @@ void Animation::Move(XYZ how) } } -void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char *modelfilename, char *model2filename, char *model3filename, char *model4filename, char *model5filename, char *model6filename, char *model7filename, char *modellowfilename, char *modelclothesfilename, bool aclothes) +void Skeleton::Load(const char *filename, const char *lowfilename, const char *clothesfilename, + const char *modelfilename, const char *model2filename, + const char *model3filename, const char *model4filename, + const char *model5filename, const char *model6filename, + const char *model7filename, const char *modellowfilename, + const char *modelclothesfilename, bool aclothes) { static GLfloat M[16]; static int parentID; @@ -1123,6 +1152,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char LOGFUNC; + newload=0; num_models=7; @@ -1176,7 +1206,7 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char drawmodelclothes.CalculateNormals(0); } - tfile=fopen( filename, "rb" ); + tfile=fopen( ConvertFileName(filename), "rb" ); if(1){ funpackf(tfile, "Bi", &num_joints); //joints.resize(num_joints); @@ -1229,8 +1259,8 @@ void Skeleton::Load(char *filename,char *lowfilename,char *clothesfilename, char funpackf(tfile, "Bi", &lowforwardjoints[j]); } for(j=0;j