2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "openal_wrapper.h"
24 #include "Animation.h"
26 extern float screenwidth,screenheight;
27 extern float viewdistance;
29 extern XYZ lightlocation;
30 extern float lightambient[3],lightbrightness[3];
31 extern float fadestart;
32 extern float texscale;
35 extern Skeleton testskeleton;
37 extern int channels[100];
38 extern Terrain terrain;
39 //extern Sprites sprites;
40 extern int kTextureSize;
41 extern float texdetail;
42 extern float realtexdetail;
43 extern float terraindetail;
45 extern Objects objects;
47 extern bool cellophane;
48 extern GLubyte bloodText[512*512*3];
49 extern GLubyte wolfbloodText[512*512*3];
50 extern bool ismotionblur;
51 extern bool trilinear;
53 extern bool musictoggle;
54 extern int environment;
55 extern bool ambientsound;
56 extern float multiplier;
57 extern int netdatanew;
59 extern bool stillloading;
60 extern TGAImageRec texture;
64 extern int oldmainmenu;
65 extern bool visibleloading;
66 extern int loadscreencolor;
67 extern float flashamount,flashr,flashg,flashb;
68 extern int flashdelay;
69 extern int whichjointstartarray[26];
70 extern int whichjointendarray[26];
71 extern int difficulty;
72 extern float tintr,tintg,tintb;
73 extern float slomospeed;
74 extern char mapname[256];
75 extern bool gamestarted;
77 extern int numdialogues;
78 extern int numdialogueboxes[20];
79 extern int dialoguetype[20];
80 extern int dialogueboxlocation[20][20];
81 extern float dialogueboxcolor[20][20][3];
82 extern int dialogueboxsound[20][20];
83 extern char dialoguetext[20][20][128];
84 extern char dialoguename[20][20][64];
85 extern XYZ dialoguecamera[20][20];
86 extern float dialoguecamerarotation[20][20];
87 extern float dialoguecamerarotation2[20][20];
88 extern int indialogue;
89 extern int whichdialogue;
90 extern float dialoguetime;
92 extern float accountcampaignhighscore[10];
93 extern float accountcampaignfasttime[10];
94 extern float accountcampaignscore[10];
95 extern float accountcampaigntime[10];
97 extern int accountcampaignchoicesmade[10];
98 extern int accountcampaignchoices[10][5000];
100 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
101 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
103 void LOG(const std::string &fmt, ...)
105 // !!! FIXME: write me.
109 Game::TextureList Game::textures;
118 accountactive->endGame();
122 Account::saveFile(":Data:Users", accountactive);
124 TexIter it = textures.begin();
125 for (; it != textures.end(); ++it)
127 if (glIsTexture(it->second))
128 glDeleteTextures(1, &it->second);
132 LOG("Shutting down sound system...");
134 OPENAL_StopSound(OPENAL_ALL);
136 // this is causing problems on Linux, but we'll force an _exit() a little
137 // later in the shutdown process. --ryan.
140 for (i=0; i < sounds_count; ++i)
142 OPENAL_Sample_Free(samp[i]);
155 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
161 LOG(std::string("Loading texture...") + fileName);
163 // Fix filename so that is os appropreate
164 char * fixedFN = ConvertFileName(fileName);
166 unsigned char fileNamep[256];
167 CopyCStringToPascal(fixedFN, fileNamep);
169 upload_image( fileNamep ,hasalpha);
171 // std::string fname(fileName);
172 // std::transform(fname.begin(), fname.end(), tolower);
173 // TexIter it = textures.find(fname);
177 //if(textures.end() == it)
180 if ( texture.bpp == 24 )
185 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
188 glGenTextures( 1, textureid );
189 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
191 glBindTexture( GL_TEXTURE_2D, *textureid);
192 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
193 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
194 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
195 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
197 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
201 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
209 LOG(std::string("Loading texture (S)...") + fileName);
212 unsigned char fileNamep[256];
213 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
215 upload_image( fileNamep ,0);
216 //LoadTGA( fileName );
218 // std::string fname(fileName);
219 // std::transform(fname.begin(), fname.end(), tolower);
220 // TexIter it = textures.find(fname);
224 //if(textures.end() == it)
226 bytesPerPixel=texture.bpp/8;
229 if ( texture.bpp == 24 )
234 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
236 if(!*textureid)glGenTextures( 1, textureid );
237 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
239 glBindTexture( GL_TEXTURE_2D, *textureid);
240 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
241 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
242 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
243 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
246 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
247 if((i+1)%4||type==GL_RGB){
248 array[tempnum]=texture.data[i];
253 *skinsize=texture.sizeX;
255 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
257 // textures.insert(std::make_pair(fname, *textureid));
261 // *textureid = it->second;
265 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
272 LOG(std::string("Loading (S)...") + fileName);
275 float temptexdetail=texdetail;
277 //upload_image( fileName );
278 //LoadTGA( fileName );
280 // Converting file to something os specific
281 char * fixedFN = ConvertFileName(fileName);
284 unsigned char fileNamep[256];
285 CopyCStringToPascal(fixedFN, fileNamep);
287 upload_image( fileNamep ,0);
288 texdetail=temptexdetail;
292 bytesPerPixel=texture.bpp/8;
295 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
296 if((i+1)%4||bytesPerPixel==3){
297 array[tempnum]=texture.data[i];
304 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
311 //upload_image( fileName );
312 //LoadTGA( fileName );
314 unsigned char fileNamep[256];
315 CopyCStringToPascal(fileName,fileNamep);
318 opened=upload_image( fileNamep ,1);
331 bytesPerPixel=texture.bpp/8;
335 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
336 if(bytesPerPixel==3)alphanum=255;
337 else if((i+1)%4==0)alphanum=texture.data[i];
339 if((i+1)%4||bytesPerPixel==3){
340 if((i%4)==0)texture.data[i]*=tintr;
341 if((i%4)==1)texture.data[i]*=tintg;
342 if((i%4)==2)texture.data[i]*=tintb;
343 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
353 //***************> ResizeGLScene() <******/
354 GLvoid Game::ReSizeGLScene(float fov, float pnear)
361 glViewport(0,0,screenwidth,screenheight);
363 glMatrixMode(GL_PROJECTION);
366 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
368 glMatrixMode(GL_MODELVIEW);
372 void Game::LoadingScreen()
374 static float loadprogress,minprogress,maxprogress;
375 static AbsoluteTime time = {0,0};
376 static AbsoluteTime frametime = {0,0};
377 AbsoluteTime currTime = UpTime ();
378 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
380 if (0 > deltaTime) // if negative microseconds
381 deltaTime /= -1000000.0;
382 else // else milliseconds
385 multiplier=deltaTime;
386 if(multiplier<.001)multiplier=.001;
387 if(multiplier>10)multiplier=10;
389 frametime = currTime; // reset for next time interval
394 glClearColor(0,0,0,1);
395 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
398 loadtime+=multiplier*4;
400 loadprogress=loadtime;
401 if(loadprogress>100)loadprogress=100;
403 //loadprogress=abs(Random()%100);
407 glEnable(GL_TEXTURE_2D);
408 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
409 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
410 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
411 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
412 glDisable(GL_CULL_FACE);
413 glDisable(GL_LIGHTING);
415 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
416 glPushMatrix(); // Store The Projection Matrix
417 glLoadIdentity(); // Reset The Projection Matrix
418 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
419 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
420 glPushMatrix(); // Store The Modelview Matrix
421 glLoadIdentity(); // Reset The Modelview Matrix
422 glTranslatef(screenwidth/2,screenheight/2,0);
423 glScalef((float)screenwidth/2,(float)screenheight/2,1);
424 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
426 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
427 //glColor4f(1,1,1,1);
428 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
429 if(loadscreencolor==1)glColor4f(1,0,0,1);
430 if(loadscreencolor==2)glColor4f(0,1,0,1);
431 if(loadscreencolor==3)glColor4f(0,0,1,1);
432 if(loadscreencolor==4)glColor4f(1,1,0,1);
433 if(loadscreencolor==5)glColor4f(1,0,1,1);
436 //glScalef(.25,.25,.25);
438 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
439 glVertex3f(-1, -1, 0.0f);
440 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
441 glVertex3f(1, -1, 0.0f);
442 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
443 glVertex3f(1, 1, 0.0f);
444 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
445 glVertex3f(-1, 1, 0.0f);
450 //glScalef(.25,.25,.25);
452 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
453 glVertex3f(-1, -1, 0.0f);
454 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
455 glVertex3f(1, -1, 0.0f);
456 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
457 glVertex3f(1, 1, 0.0f);
458 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
459 glVertex3f(-1, 1, 0.0f);
462 glDisable(GL_TEXTURE_2D);
463 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
464 glPopMatrix(); // Restore The Old Projection Matrix
465 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
466 glPopMatrix(); // Restore The Old Projection Matrix
470 glEnable(GL_TEXTURE_2D);
471 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
472 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
473 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
474 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
475 glDisable(GL_CULL_FACE);
476 glDisable(GL_LIGHTING);
478 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
479 glPushMatrix(); // Store The Projection Matrix
480 glLoadIdentity(); // Reset The Projection Matrix
481 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
482 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
483 glPushMatrix(); // Store The Modelview Matrix
484 glLoadIdentity(); // Reset The Modelview Matrix
485 glTranslatef(screenwidth/2,screenheight/2,0);
486 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
487 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
489 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
490 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
491 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
492 if(loadscreencolor==1)glColor4f(1,0,0,1);
493 if(loadscreencolor==2)glColor4f(0,1,0,1);
494 if(loadscreencolor==3)glColor4f(0,0,1,1);
495 if(loadscreencolor==4)glColor4f(1,1,0,1);
496 if(loadscreencolor==5)glColor4f(1,0,1,1);
499 //glScalef(.25,.25,.25);
501 glTexCoord2f(0+.5,0+.5);
502 glVertex3f(-1, -1, 0.0f);
503 glTexCoord2f(1+.5,0+.5);
504 glVertex3f(1, -1, 0.0f);
505 glTexCoord2f(1+.5,1+.5);
506 glVertex3f(1, 1, 0.0f);
507 glTexCoord2f(0+.5,1+.5);
508 glVertex3f(-1, 1, 0.0f);
511 glDisable(GL_TEXTURE_2D);
512 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
513 glPopMatrix(); // Restore The Old Projection Matrix
514 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
515 glPopMatrix(); // Restore The Old Projection Matrix
519 glEnable(GL_TEXTURE_2D);
520 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
521 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
522 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
523 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
524 glDisable(GL_CULL_FACE);
525 glDisable(GL_LIGHTING);
527 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
528 glPushMatrix(); // Store The Projection Matrix
529 glLoadIdentity(); // Reset The Projection Matrix
530 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
531 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
532 glPushMatrix(); // Store The Modelview Matrix
533 glLoadIdentity(); // Reset The Modelview Matrix
534 glTranslatef(screenwidth/2,screenheight/2,0);
535 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
536 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
538 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
540 //glScalef(.25,.25,.25);
542 glTexCoord2f(0+.2,0+.8);
543 glVertex3f(-1, -1, 0.0f);
544 glTexCoord2f(1+.2,0+.8);
545 glVertex3f(1, -1, 0.0f);
546 glTexCoord2f(1+.2,1+.8);
547 glVertex3f(1, 1, 0.0f);
548 glTexCoord2f(0+.2,1+.8);
549 glVertex3f(-1, 1, 0.0f);
552 glDisable(GL_TEXTURE_2D);
553 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
554 glPopMatrix(); // Restore The Old Projection Matrix
555 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
556 glPopMatrix(); // Restore The Old Projection Matrix
562 glEnable(GL_TEXTURE_2D);
563 static char string[256]="";
564 sprintf (string, "LOADING... %d%",(int)loadprogress);
566 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
567 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
568 text.glPrint(280,125,string,1,1,640,480);
572 if(flashamount>1)flashamount=1;
573 if(flashdelay<=0)flashamount-=multiplier;
575 if(flashamount<0)flashamount=0;
576 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
577 glDisable(GL_CULL_FACE);
578 glDisable(GL_LIGHTING);
579 glDisable(GL_TEXTURE_2D);
581 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
582 glPushMatrix(); // Store The Projection Matrix
583 glLoadIdentity(); // Reset The Projection Matrix
584 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
585 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
586 glPushMatrix(); // Store The Modelview Matrix
587 glLoadIdentity(); // Reset The Modelview Matrix
588 glScalef(screenwidth,screenheight,1);
589 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
591 glColor4f(flashr,flashg,flashb,flashamount);
593 glVertex3f(0, 0, 0.0f);
594 glVertex3f(256, 0, 0.0f);
595 glVertex3f(256, 256, 0.0f);
596 glVertex3f(0, 256, 0.0f);
598 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
599 glPopMatrix(); // Restore The Old Projection Matrix
600 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
601 glPopMatrix(); // Restore The Old Projection Matrix
602 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
603 glEnable(GL_CULL_FACE);
613 void Game::FadeLoadingScreen(float howmuch)
615 static float loadprogress,minprogress,maxprogress;
620 glClearColor(0,0,0,1);
621 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
623 loadprogress=howmuch;
625 //loadprogress=abs(Random()%100);
629 //glEnable(GL_TEXTURE_2D);
630 glDisable(GL_TEXTURE_2D);
631 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
632 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
633 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
634 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
635 glDisable(GL_CULL_FACE);
636 glDisable(GL_LIGHTING);
638 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
639 glPushMatrix(); // Store The Projection Matrix
640 glLoadIdentity(); // Reset The Projection Matrix
641 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
642 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
643 glPushMatrix(); // Store The Modelview Matrix
644 glLoadIdentity(); // Reset The Modelview Matrix
645 glTranslatef(screenwidth/2,screenheight/2,0);
646 glScalef((float)screenwidth/2,(float)screenheight/2,1);
647 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
649 glColor4f(loadprogress/100,0,0,1);
650 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
651 if(loadscreencolor==1)glColor4f(1,0,0,1);
652 if(loadscreencolor==2)glColor4f(0,1,0,1);
653 if(loadscreencolor==3)glColor4f(0,0,1,1);
654 if(loadscreencolor==4)glColor4f(1,1,0,1);
655 if(loadscreencolor==5)glColor4f(1,0,1,1);
658 //glScalef(.25,.25,.25);
661 glVertex3f(-1, -1, 0.0f);
663 glVertex3f(1, -1, 0.0f);
665 glVertex3f(1, 1, 0.0f);
667 glVertex3f(-1, 1, 0.0f);
670 glDisable(GL_TEXTURE_2D);
671 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
672 glPopMatrix(); // Restore The Old Projection Matrix
673 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
674 glPopMatrix(); // Restore The Old Projection Matrix
679 glEnable(GL_TEXTURE_2D);
680 static char string[256]="";
681 sprintf (string, "LOADING... %d%",(int)loadprogress);
683 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
684 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
685 text.glPrint(280,125,string,1,1,640,480);
692 void Game::InitGame()
695 ProcessSerialNumber PSN;
696 ProcessInfoRec pinfo;
699 /* set up process serial number */
700 PSN.highLongOfPSN = 0;
701 PSN.lowLongOfPSN = kCurrentProcess;
702 /* set up info block */
703 pinfo.processInfoLength = sizeof(pinfo);
704 pinfo.processName = NULL;
705 pinfo.processAppSpec = &pspec;
706 /* grab the vrefnum and directory */
707 err = GetProcessInformation(&PSN, &pinfo);
709 vRefNum = pspec.vRefNum;
720 numchallengelevels=14;
722 accountactive=Account::loadFile(":Data:Users");
728 whichjointstartarray[0]=righthip;
729 whichjointendarray[0]=rightfoot;
731 whichjointstartarray[1]=righthip;
732 whichjointendarray[1]=rightankle;
734 whichjointstartarray[2]=righthip;
735 whichjointendarray[2]=rightknee;
737 whichjointstartarray[3]=rightknee;
738 whichjointendarray[3]=rightankle;
740 whichjointstartarray[4]=rightankle;
741 whichjointendarray[4]=rightfoot;
743 whichjointstartarray[5]=lefthip;
744 whichjointendarray[5]=leftfoot;
746 whichjointstartarray[6]=lefthip;
747 whichjointendarray[6]=leftankle;
749 whichjointstartarray[7]=lefthip;
750 whichjointendarray[7]=leftknee;
752 whichjointstartarray[8]=leftknee;
753 whichjointendarray[8]=leftankle;
755 whichjointstartarray[9]=leftankle;
756 whichjointendarray[9]=leftfoot;
758 whichjointstartarray[10]=abdomen;
759 whichjointendarray[10]=rightshoulder;
761 whichjointstartarray[11]=abdomen;
762 whichjointendarray[11]=rightelbow;
764 whichjointstartarray[12]=abdomen;
765 whichjointendarray[12]=rightwrist;
767 whichjointstartarray[13]=abdomen;
768 whichjointendarray[13]=righthand;
770 whichjointstartarray[14]=rightshoulder;
771 whichjointendarray[14]=rightelbow;
773 whichjointstartarray[15]=rightelbow;
774 whichjointendarray[15]=rightwrist;
776 whichjointstartarray[16]=rightwrist;
777 whichjointendarray[16]=righthand;
779 whichjointstartarray[17]=abdomen;
780 whichjointendarray[17]=leftshoulder;
782 whichjointstartarray[18]=abdomen;
783 whichjointendarray[18]=leftelbow;
785 whichjointstartarray[19]=abdomen;
786 whichjointendarray[19]=leftwrist;
788 whichjointstartarray[20]=abdomen;
789 whichjointendarray[20]=lefthand;
791 whichjointstartarray[21]=leftshoulder;
792 whichjointendarray[21]=leftelbow;
794 whichjointstartarray[22]=leftelbow;
795 whichjointendarray[22]=leftwrist;
797 whichjointstartarray[23]=leftwrist;
798 whichjointendarray[23]=lefthand;
800 whichjointstartarray[24]=abdomen;
801 whichjointendarray[24]=neck;
803 whichjointstartarray[25]=neck;
804 whichjointendarray[25]=head;
806 FadeLoadingScreen(0);
810 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
812 int temptexdetail=texdetail;
814 text.LoadFontTexture(":Data:Textures:Font.png");
816 texdetail=temptexdetail;
818 FadeLoadingScreen(10);
834 memset(channels, 0xff, sizeof(channels));
836 LOG("Initializing sound system...");
841 extern bool cmdline(const char *cmd);
842 unsigned char rc = 0;
843 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
844 if (cmdline("forceoss")) // ...but let user override that.
845 output = OPENAL_OUTPUT_OSS;
846 else if (cmdline("nosound"))
847 output = OPENAL_OUTPUT_NOSOUND;
849 OPENAL_SetOutput(output);
850 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
852 // if we tried ALSA and failed, fall back to OSS.
853 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
856 output = OPENAL_OUTPUT_OSS;
857 OPENAL_SetOutput(output);
858 rc = OPENAL_Init(44100, 32, 0);
865 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
866 OPENAL_SetOutput(output);
867 rc = OPENAL_Init(44100, 32, 0);
870 OPENAL_Init(44100, 32, 0);
873 OPENAL_SetSFXMasterVolume((int)(volume*255));
877 PlayStreamEx(stream_music3, samp[stream_music3], 0, true);
878 OPENAL_SetPaused(channels[stream_music3], false);
879 OPENAL_SetVolume(channels[stream_music3], 256);
882 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
884 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
885 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
886 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
888 temptexdetail=texdetail;
889 if(texdetail>2)texdetail=2;
890 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
891 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
892 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
893 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
894 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
895 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
896 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
897 texdetail=temptexdetail;
902 FadeLoadingScreen(95);
913 newscreenwidth=screenwidth;
914 newscreenheight=screenheight;
918 void Game::LoadStuff()
920 static float temptexdetail;
921 static float viewdistdetail;
922 static int i,j,texsize;
929 /*musicvolume[3]=512;
930 PlaySoundEx( music4, samp[music4], NULL, true);
931 OPENAL_SetPaused(channels[music4], false);
932 OPENAL_SetVolume(channels[music4], 512);
938 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
940 for(i=0;i<maxplayers;i++)
942 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
944 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
946 player[i].skeleton.drawmodel.textureptr=0;;
949 //temptexdetail=texdetail;
952 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
953 //texdetail=temptexdetail;
955 temptexdetail=texdetail;
957 text.LoadFontTexture(":Data:Textures:Font.png");
959 texdetail=temptexdetail;
964 viewdistance=50*megascale*viewdistdetail;
984 realtexdetail=texdetail;
987 if(texdetail<1)texdetail=1;
988 realtexdetail=texdetail*4;
994 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
996 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
998 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
1002 LOG("Loading weapon data...");
1004 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
1005 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1006 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1007 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1008 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1009 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1010 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1012 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1013 weapons.throwingknifemodel.Scale(.001,.001,.001);
1014 //weapons.throwingknifemodel.Rotate(0,0,-90);
1015 weapons.throwingknifemodel.Rotate(90,0,0);
1016 weapons.throwingknifemodel.Rotate(0,90,0);
1017 weapons.throwingknifemodel.flat=0;
1018 weapons.throwingknifemodel.CalculateNormals(1);
1019 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1021 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1022 weapons.swordmodel.Scale(.001,.001,.001);
1023 //weapons.swordmodel.Rotate(0,0,-90);
1024 weapons.swordmodel.Rotate(90,0,0);
1025 weapons.swordmodel.Rotate(0,90,0);
1026 weapons.swordmodel.Rotate(0,0,90);
1027 weapons.swordmodel.flat=1;
1028 weapons.swordmodel.CalculateNormals(1);
1029 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1031 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1032 weapons.staffmodel.Scale(.005,.005,.005);
1033 //weapons.staffmodel.Rotate(0,0,-90);
1034 weapons.staffmodel.Rotate(90,0,0);
1035 weapons.staffmodel.Rotate(0,90,0);
1036 weapons.staffmodel.Rotate(0,0,90);
1037 weapons.staffmodel.flat=1;
1038 weapons.staffmodel.CalculateNormals(1);
1039 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1041 //temptexdetail=texdetail;
1042 //if(texdetail>4)texdetail=4;
1043 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1045 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1047 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1049 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1052 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1054 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1056 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1058 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1060 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1062 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1064 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1066 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1067 //texdetail=temptexdetail;
1068 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1072 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1074 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1077 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1080 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1081 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1082 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1083 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1084 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1085 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1086 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1087 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1088 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1089 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1090 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1094 ReSizeGLScene(90,.01);
1101 if(detail)kTextureSize=1024;
1102 if(detail==1)kTextureSize=512;
1103 if(detail==0)kTextureSize=256;
1106 //drawmode=motionblurmode;
1108 //Set up distant light
1112 light.ambient[0]=.2;
1113 light.ambient[1]=.2;
1114 light.ambient[2]=.24;
1117 light.location.z=-.2;
1118 Normalise(&light.location);
1128 texscale=.2/megascale/viewdistdetail;
1129 terrain.scale=3*megascale*terraindetail*viewdistdetail;
1131 viewer.x=terrain.size/2*terrain.scale;
1132 viewer.z=terrain.size/2*terrain.scale;
1134 hawk.load((char *)":Data:Models:hawk.solid",1);
1135 hawk.Scale(.03,.03,.03);
1136 hawk.Rotate(90,1,1);
1137 hawk.CalculateNormals(0);
1138 hawk.ScaleNormals(-1,-1,-1);
1139 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1140 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1141 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1144 eye.load((char *)":Data:Models:eye.solid",1);
1145 eye.Scale(.03,.03,.03);
1146 eye.CalculateNormals(0);
1148 cornea.load((char *)":Data:Models:cornea.solid",1);
1149 cornea.Scale(.03,.03,.03);
1150 cornea.CalculateNormals(0);
1152 iris.load((char *)":Data:Models:iris.solid",1);
1153 iris.Scale(.03,.03,.03);
1154 iris.CalculateNormals(0);
1156 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1157 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1165 //if(targetlevel!=7)
1166 Loadlevel(targetlevel);
1169 rabbitcoords=player[0].coords;
1170 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1172 loadAllAnimations();
1173 //Fix knife stab, too lazy to do it manually
1177 for(i=0;i<player[0].skeleton.num_joints;i++){
1178 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1179 animation[knifesneakattackanim].position[i][j]+=moveamount;
1186 for(i=0;i<player[0].skeleton.num_joints;i++){
1187 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1188 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1195 for(i=0;i<player[0].skeleton.num_joints;i++){
1196 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1197 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1198 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1199 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1201 animation[dead1anim].speed[0]=0.001;
1202 animation[dead2anim].speed[0]=0.001;
1203 animation[dead3anim].speed[0]=0.001;
1204 animation[dead4anim].speed[0]=0.001;
1206 animation[dead1anim].speed[1]=0.001;
1207 animation[dead2anim].speed[1]=0.001;
1208 animation[dead3anim].speed[1]=0.001;
1209 animation[dead4anim].speed[1]=0.001;
1211 for(i=0;i<player[0].skeleton.num_joints;i++){
1212 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1213 animation[swordsneakattackanim].position[i][j]+=moveamount;
1218 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1219 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1225 for(i=0;i<player[0].skeleton.num_joints;i++){
1226 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1227 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1231 for(i=0;i<player[0].skeleton.num_joints;i++){
1232 for(j=0;j<animation[sleepanim].numframes;j++){
1233 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1239 temptexdetail=texdetail;
1241 texdetail=temptexdetail;
1248 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1250 glGenTextures( 1, &screentexture );
1251 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1254 glEnable(GL_TEXTURE_2D);
1255 glBindTexture( GL_TEXTURE_2D, screentexture);
1256 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1257 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1259 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1263 float gLoc[3]={0,0,0};
1264 float vel[3]={0,0,0};
1265 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1266 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1267 OPENAL_SetVolume(channels[fireendsound], 256);
1268 OPENAL_SetPaused(channels[fireendsound], false);