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 void LOG(const std::string &fmt, ...)
102 // !!! FIXME: write me.
106 Game::TextureList Game::textures;
115 accountactive->endGame();
119 Account::saveFile(":Data:Users", accountactive);
121 TexIter it = textures.begin();
122 for (; it != textures.end(); ++it)
124 if (glIsTexture(it->second))
125 glDeleteTextures(1, &it->second);
129 LOG("Shutting down sound system...");
131 OPENAL_StopSound(OPENAL_ALL);
133 // this is causing problems on Linux, but we'll force an _exit() a little
134 // later in the shutdown process. --ryan.
137 for (i=0; i < sounds_count; ++i)
139 OPENAL_Sample_Free(samp[i]);
152 void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
158 LOG(std::string("Loading texture...") + fileName);
160 // Fix filename so that is os appropreate
161 char * fixedFN = ConvertFileName(fileName);
163 unsigned char fileNamep[256];
164 CopyCStringToPascal(fixedFN, fileNamep);
166 upload_image( fileNamep ,hasalpha);
168 // std::string fname(fileName);
169 // std::transform(fname.begin(), fname.end(), tolower);
170 // TexIter it = textures.find(fname);
174 //if(textures.end() == it)
177 if ( texture.bpp == 24 )
182 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
185 glGenTextures( 1, textureid );
186 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
188 glBindTexture( GL_TEXTURE_2D, *textureid);
189 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
190 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
191 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
192 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
194 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
198 void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize)
206 LOG(std::string("Loading texture (S)...") + fileName);
209 unsigned char fileNamep[256];
210 CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
212 upload_image( fileNamep ,0);
213 //LoadTGA( fileName );
215 // std::string fname(fileName);
216 // std::transform(fname.begin(), fname.end(), tolower);
217 // TexIter it = textures.find(fname);
221 //if(textures.end() == it)
223 bytesPerPixel=texture.bpp/8;
226 if ( texture.bpp == 24 )
231 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
233 if(!*textureid)glGenTextures( 1, textureid );
234 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
236 glBindTexture( GL_TEXTURE_2D, *textureid);
237 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
238 if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
239 if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
240 if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
243 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
244 if((i+1)%4||type==GL_RGB){
245 array[tempnum]=texture.data[i];
250 *skinsize=texture.sizeX;
252 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
254 // textures.insert(std::make_pair(fname, *textureid));
258 // *textureid = it->second;
262 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
269 LOG(std::string("Loading (S)...") + fileName);
272 float temptexdetail=texdetail;
274 //upload_image( fileName );
275 //LoadTGA( fileName );
277 // Converting file to something os specific
278 char * fixedFN = ConvertFileName(fileName);
281 unsigned char fileNamep[256];
282 CopyCStringToPascal(fixedFN, fileNamep);
284 upload_image( fileNamep ,0);
285 texdetail=temptexdetail;
289 bytesPerPixel=texture.bpp/8;
292 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
293 if((i+1)%4||bytesPerPixel==3){
294 array[tempnum]=texture.data[i];
301 bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
308 //upload_image( fileName );
309 //LoadTGA( fileName );
311 unsigned char fileNamep[256];
312 CopyCStringToPascal(fileName,fileNamep);
315 opened=upload_image( fileNamep ,1);
328 bytesPerPixel=texture.bpp/8;
332 for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){
333 if(bytesPerPixel==3)alphanum=255;
334 else if((i+1)%4==0)alphanum=texture.data[i];
336 if((i+1)%4||bytesPerPixel==3){
337 if((i%4)==0)texture.data[i]*=tintr;
338 if((i%4)==1)texture.data[i]*=tintg;
339 if((i%4)==2)texture.data[i]*=tintb;
340 array[tempnum]=(float)array[tempnum]*(1-alphanum/255)+(float)texture.data[i]*(alphanum/255);
350 //***************> ResizeGLScene() <******/
351 GLvoid Game::ReSizeGLScene(float fov, float pnear)
358 glViewport(0,0,screenwidth,screenheight);
360 glMatrixMode(GL_PROJECTION);
363 gluPerspective(fov,(GLfloat)screenwidth/(GLfloat)screenheight,pnear,viewdistance);
365 glMatrixMode(GL_MODELVIEW);
369 void Game::LoadingScreen()
371 static float loadprogress,minprogress,maxprogress;
372 static AbsoluteTime time = {0,0};
373 static AbsoluteTime frametime = {0,0};
374 AbsoluteTime currTime = UpTime ();
375 double deltaTime = (float) AbsoluteDeltaToDuration (currTime, frametime);
377 if (0 > deltaTime) // if negative microseconds
378 deltaTime /= -1000000.0;
379 else // else milliseconds
382 multiplier=deltaTime;
383 if(multiplier<.001)multiplier=.001;
384 if(multiplier>10)multiplier=10;
386 frametime = currTime; // reset for next time interval
391 glClearColor(0,0,0,1);
392 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
395 loadtime+=multiplier*4;
397 loadprogress=loadtime;
398 if(loadprogress>100)loadprogress=100;
400 //loadprogress=abs(Random()%100);
404 glEnable(GL_TEXTURE_2D);
405 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
406 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
407 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
408 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
409 glDisable(GL_CULL_FACE);
410 glDisable(GL_LIGHTING);
412 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
413 glPushMatrix(); // Store The Projection Matrix
414 glLoadIdentity(); // Reset The Projection Matrix
415 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
416 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
417 glPushMatrix(); // Store The Modelview Matrix
418 glLoadIdentity(); // Reset The Modelview Matrix
419 glTranslatef(screenwidth/2,screenheight/2,0);
420 glScalef((float)screenwidth/2,(float)screenheight/2,1);
421 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
423 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
424 //glColor4f(1,1,1,1);
425 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
426 if(loadscreencolor==1)glColor4f(1,0,0,1);
427 if(loadscreencolor==2)glColor4f(0,1,0,1);
428 if(loadscreencolor==3)glColor4f(0,0,1,1);
429 if(loadscreencolor==4)glColor4f(1,1,0,1);
430 if(loadscreencolor==5)glColor4f(1,0,1,1);
433 //glScalef(.25,.25,.25);
435 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
436 glVertex3f(-1, -1, 0.0f);
437 glTexCoord2f(.1-loadprogress/100,0+loadprogress/100+.3);
438 glVertex3f(1, -1, 0.0f);
439 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
440 glVertex3f(1, 1, 0.0f);
441 glTexCoord2f(.1-loadprogress/100,1+loadprogress/100+.3);
442 glVertex3f(-1, 1, 0.0f);
447 //glScalef(.25,.25,.25);
449 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
450 glVertex3f(-1, -1, 0.0f);
451 glTexCoord2f(.4+loadprogress/100,0+loadprogress/100);
452 glVertex3f(1, -1, 0.0f);
453 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
454 glVertex3f(1, 1, 0.0f);
455 glTexCoord2f(.4+loadprogress/100,1+loadprogress/100);
456 glVertex3f(-1, 1, 0.0f);
459 glDisable(GL_TEXTURE_2D);
460 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
461 glPopMatrix(); // Restore The Old Projection Matrix
462 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
463 glPopMatrix(); // Restore The Old Projection Matrix
467 glEnable(GL_TEXTURE_2D);
468 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
469 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
470 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
471 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
472 glDisable(GL_CULL_FACE);
473 glDisable(GL_LIGHTING);
475 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
476 glPushMatrix(); // Store The Projection Matrix
477 glLoadIdentity(); // Reset The Projection Matrix
478 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
479 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
480 glPushMatrix(); // Store The Modelview Matrix
481 glLoadIdentity(); // Reset The Modelview Matrix
482 glTranslatef(screenwidth/2,screenheight/2,0);
483 glScalef((float)screenwidth/2*(1.5-(loadprogress)/200),(float)screenheight/2*(1.5-(loadprogress)/200),1);
484 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
486 //glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
487 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,1);
488 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
489 if(loadscreencolor==1)glColor4f(1,0,0,1);
490 if(loadscreencolor==2)glColor4f(0,1,0,1);
491 if(loadscreencolor==3)glColor4f(0,0,1,1);
492 if(loadscreencolor==4)glColor4f(1,1,0,1);
493 if(loadscreencolor==5)glColor4f(1,0,1,1);
496 //glScalef(.25,.25,.25);
498 glTexCoord2f(0+.5,0+.5);
499 glVertex3f(-1, -1, 0.0f);
500 glTexCoord2f(1+.5,0+.5);
501 glVertex3f(1, -1, 0.0f);
502 glTexCoord2f(1+.5,1+.5);
503 glVertex3f(1, 1, 0.0f);
504 glTexCoord2f(0+.5,1+.5);
505 glVertex3f(-1, 1, 0.0f);
508 glDisable(GL_TEXTURE_2D);
509 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
510 glPopMatrix(); // Restore The Old Projection Matrix
511 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
512 glPopMatrix(); // Restore The Old Projection Matrix
516 glEnable(GL_TEXTURE_2D);
517 glBindTexture( GL_TEXTURE_2D, loadscreentexture);
518 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
519 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
520 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
521 glDisable(GL_CULL_FACE);
522 glDisable(GL_LIGHTING);
524 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
525 glPushMatrix(); // Store The Projection Matrix
526 glLoadIdentity(); // Reset The Projection Matrix
527 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
528 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
529 glPushMatrix(); // Store The Modelview Matrix
530 glLoadIdentity(); // Reset The Modelview Matrix
531 glTranslatef(screenwidth/2,screenheight/2,0);
532 glScalef((float)screenwidth/2*(100+loadprogress)/100,(float)screenheight/2*(100+loadprogress)/100,1);
533 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
535 glColor4f(loadprogress/100,loadprogress/100,loadprogress/100,.4);
537 //glScalef(.25,.25,.25);
539 glTexCoord2f(0+.2,0+.8);
540 glVertex3f(-1, -1, 0.0f);
541 glTexCoord2f(1+.2,0+.8);
542 glVertex3f(1, -1, 0.0f);
543 glTexCoord2f(1+.2,1+.8);
544 glVertex3f(1, 1, 0.0f);
545 glTexCoord2f(0+.2,1+.8);
546 glVertex3f(-1, 1, 0.0f);
549 glDisable(GL_TEXTURE_2D);
550 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
551 glPopMatrix(); // Restore The Old Projection Matrix
552 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
553 glPopMatrix(); // Restore The Old Projection Matrix
559 glEnable(GL_TEXTURE_2D);
560 static char string[256]="";
561 sprintf (string, "LOADING... %d%",(int)loadprogress);
563 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
564 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
565 text.glPrint(280,125,string,1,1,640,480);
569 if(flashamount>1)flashamount=1;
570 if(flashdelay<=0)flashamount-=multiplier;
572 if(flashamount<0)flashamount=0;
573 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
574 glDisable(GL_CULL_FACE);
575 glDisable(GL_LIGHTING);
576 glDisable(GL_TEXTURE_2D);
578 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
579 glPushMatrix(); // Store The Projection Matrix
580 glLoadIdentity(); // Reset The Projection Matrix
581 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
582 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
583 glPushMatrix(); // Store The Modelview Matrix
584 glLoadIdentity(); // Reset The Modelview Matrix
585 glScalef(screenwidth,screenheight,1);
586 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
588 glColor4f(flashr,flashg,flashb,flashamount);
590 glVertex3f(0, 0, 0.0f);
591 glVertex3f(256, 0, 0.0f);
592 glVertex3f(256, 256, 0.0f);
593 glVertex3f(0, 256, 0.0f);
595 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
596 glPopMatrix(); // Restore The Old Projection Matrix
597 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
598 glPopMatrix(); // Restore The Old Projection Matrix
599 glEnable(GL_DEPTH_TEST); // Enables Depth Testing
600 glEnable(GL_CULL_FACE);
610 void Game::FadeLoadingScreen(float howmuch)
612 static float loadprogress,minprogress,maxprogress;
617 glClearColor(0,0,0,1);
618 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
620 loadprogress=howmuch;
622 //loadprogress=abs(Random()%100);
626 //glEnable(GL_TEXTURE_2D);
627 glDisable(GL_TEXTURE_2D);
628 //glBindTexture( GL_TEXTURE_2D, loadscreentexture);
629 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
630 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
631 glDisable(GL_DEPTH_TEST); // Disables Depth Testing
632 glDisable(GL_CULL_FACE);
633 glDisable(GL_LIGHTING);
635 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
636 glPushMatrix(); // Store The Projection Matrix
637 glLoadIdentity(); // Reset The Projection Matrix
638 glOrtho(0,screenwidth,0,screenheight,-100,100); // Set Up An Ortho Screen
639 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
640 glPushMatrix(); // Store The Modelview Matrix
641 glLoadIdentity(); // Reset The Modelview Matrix
642 glTranslatef(screenwidth/2,screenheight/2,0);
643 glScalef((float)screenwidth/2,(float)screenheight/2,1);
644 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
646 glColor4f(loadprogress/100,0,0,1);
647 /*if(loadscreencolor==0)glColor4f(1,1,1,1);
648 if(loadscreencolor==1)glColor4f(1,0,0,1);
649 if(loadscreencolor==2)glColor4f(0,1,0,1);
650 if(loadscreencolor==3)glColor4f(0,0,1,1);
651 if(loadscreencolor==4)glColor4f(1,1,0,1);
652 if(loadscreencolor==5)glColor4f(1,0,1,1);
655 //glScalef(.25,.25,.25);
658 glVertex3f(-1, -1, 0.0f);
660 glVertex3f(1, -1, 0.0f);
662 glVertex3f(1, 1, 0.0f);
664 glVertex3f(-1, 1, 0.0f);
667 glDisable(GL_TEXTURE_2D);
668 glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
669 glPopMatrix(); // Restore The Old Projection Matrix
670 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
671 glPopMatrix(); // Restore The Old Projection Matrix
676 glEnable(GL_TEXTURE_2D);
677 static char string[256]="";
678 sprintf (string, "LOADING... %d%",(int)loadprogress);
680 text.glPrint(280-280*loadprogress/100/2/4,125-125*loadprogress/100/2/4,string,1,1+loadprogress/100,640,480);
681 glColor4f(1.2-loadprogress/100,1.2-loadprogress/100,1.2-loadprogress/100,1);
682 text.glPrint(280,125,string,1,1,640,480);
689 void Game::InitGame()
692 ProcessSerialNumber PSN;
693 ProcessInfoRec pinfo;
696 /* set up process serial number */
697 PSN.highLongOfPSN = 0;
698 PSN.lowLongOfPSN = kCurrentProcess;
699 /* set up info block */
700 pinfo.processInfoLength = sizeof(pinfo);
701 pinfo.processName = NULL;
702 pinfo.processAppSpec = &pspec;
703 /* grab the vrefnum and directory */
704 err = GetProcessInformation(&PSN, &pinfo);
706 vRefNum = pspec.vRefNum;
717 numchallengelevels=14;
719 accountactive=Account::loadFile(":Data:Users");
725 whichjointstartarray[0]=righthip;
726 whichjointendarray[0]=rightfoot;
728 whichjointstartarray[1]=righthip;
729 whichjointendarray[1]=rightankle;
731 whichjointstartarray[2]=righthip;
732 whichjointendarray[2]=rightknee;
734 whichjointstartarray[3]=rightknee;
735 whichjointendarray[3]=rightankle;
737 whichjointstartarray[4]=rightankle;
738 whichjointendarray[4]=rightfoot;
740 whichjointstartarray[5]=lefthip;
741 whichjointendarray[5]=leftfoot;
743 whichjointstartarray[6]=lefthip;
744 whichjointendarray[6]=leftankle;
746 whichjointstartarray[7]=lefthip;
747 whichjointendarray[7]=leftknee;
749 whichjointstartarray[8]=leftknee;
750 whichjointendarray[8]=leftankle;
752 whichjointstartarray[9]=leftankle;
753 whichjointendarray[9]=leftfoot;
755 whichjointstartarray[10]=abdomen;
756 whichjointendarray[10]=rightshoulder;
758 whichjointstartarray[11]=abdomen;
759 whichjointendarray[11]=rightelbow;
761 whichjointstartarray[12]=abdomen;
762 whichjointendarray[12]=rightwrist;
764 whichjointstartarray[13]=abdomen;
765 whichjointendarray[13]=righthand;
767 whichjointstartarray[14]=rightshoulder;
768 whichjointendarray[14]=rightelbow;
770 whichjointstartarray[15]=rightelbow;
771 whichjointendarray[15]=rightwrist;
773 whichjointstartarray[16]=rightwrist;
774 whichjointendarray[16]=righthand;
776 whichjointstartarray[17]=abdomen;
777 whichjointendarray[17]=leftshoulder;
779 whichjointstartarray[18]=abdomen;
780 whichjointendarray[18]=leftelbow;
782 whichjointstartarray[19]=abdomen;
783 whichjointendarray[19]=leftwrist;
785 whichjointstartarray[20]=abdomen;
786 whichjointendarray[20]=lefthand;
788 whichjointstartarray[21]=leftshoulder;
789 whichjointendarray[21]=leftelbow;
791 whichjointstartarray[22]=leftelbow;
792 whichjointendarray[22]=leftwrist;
794 whichjointstartarray[23]=leftwrist;
795 whichjointendarray[23]=lefthand;
797 whichjointstartarray[24]=abdomen;
798 whichjointendarray[24]=neck;
800 whichjointstartarray[25]=neck;
801 whichjointendarray[25]=head;
803 FadeLoadingScreen(0);
807 texture.data = ( GLubyte* )malloc( 1024*1024*4 );
809 int temptexdetail=texdetail;
811 text.LoadFontTexture(":Data:Textures:Font.png");
813 texdetail=temptexdetail;
815 FadeLoadingScreen(10);
831 memset(channels, 0xff, sizeof(channels));
833 LOG("Initializing sound system...");
838 extern bool cmdline(const char *cmd);
839 unsigned char rc = 0;
840 output = OPENAL_OUTPUT_ALSA; // Try alsa first...
841 if (cmdline("forceoss")) // ...but let user override that.
842 output = OPENAL_OUTPUT_OSS;
843 else if (cmdline("nosound"))
844 output = OPENAL_OUTPUT_NOSOUND;
846 OPENAL_SetOutput(output);
847 if ((rc = OPENAL_Init(44100, 32, 0)) == false)
849 // if we tried ALSA and failed, fall back to OSS.
850 if ( (output == OPENAL_OUTPUT_ALSA) && (!cmdline("forcealsa")) )
853 output = OPENAL_OUTPUT_OSS;
854 OPENAL_SetOutput(output);
855 rc = OPENAL_Init(44100, 32, 0);
862 output = OPENAL_OUTPUT_NOSOUND; // we tried! just do silence.
863 OPENAL_SetOutput(output);
864 rc = OPENAL_Init(44100, 32, 0);
867 OPENAL_Init(44100, 32, 0);
870 OPENAL_SetSFXMasterVolume((int)(volume*255));
874 emit_stream_np(stream_music3);
876 LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
878 LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
879 LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
880 LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
882 temptexdetail=texdetail;
883 if(texdetail>2)texdetail=2;
884 LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
885 LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
886 LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
887 LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
888 LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
889 LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
890 //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
891 texdetail=temptexdetail;
896 FadeLoadingScreen(95);
907 newscreenwidth=screenwidth;
908 newscreenheight=screenheight;
912 void Game::LoadStuff()
914 static float temptexdetail;
915 static float viewdistdetail;
916 static int i,j,texsize;
923 /*musicvolume[3]=512;
924 PlaySoundEx( music4, samp[music4], NULL, true);
925 OPENAL_SetPaused(channels[music4], false);
926 OPENAL_SetVolume(channels[music4], 512);
932 //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
934 for(i=0;i<maxplayers;i++)
936 if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
938 glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
940 player[i].skeleton.drawmodel.textureptr=0;;
943 //temptexdetail=texdetail;
946 LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
947 //texdetail=temptexdetail;
949 temptexdetail=texdetail;
951 text.LoadFontTexture(":Data:Textures:Font.png");
953 texdetail=temptexdetail;
958 viewdistance=50*megascale*viewdistdetail;
978 realtexdetail=texdetail;
981 if(texdetail<1)texdetail=1;
982 realtexdetail=texdetail*4;
988 /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
990 LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
992 LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
996 LOG("Loading weapon data...");
998 LoadTexture(":Data:Textures:knife.png",&weapons.knifetextureptr,0,1);
999 LoadTexture(":Data:Textures:bloodknife.png",&weapons.bloodknifetextureptr,0,1);
1000 LoadTexture(":Data:Textures:lightbloodknife.png",&weapons.lightbloodknifetextureptr,0,1);
1001 LoadTexture(":Data:Textures:sword.jpg",&weapons.swordtextureptr,1,0);
1002 LoadTexture(":Data:Textures:Swordblood.jpg",&weapons.bloodswordtextureptr,1,0);
1003 LoadTexture(":Data:Textures:Swordbloodlight.jpg",&weapons.lightbloodswordtextureptr,1,0);
1004 LoadTexture(":Data:Textures:Staff.jpg",&weapons.stafftextureptr,1,0);
1006 weapons.throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
1007 weapons.throwingknifemodel.Scale(.001,.001,.001);
1008 //weapons.throwingknifemodel.Rotate(0,0,-90);
1009 weapons.throwingknifemodel.Rotate(90,0,0);
1010 weapons.throwingknifemodel.Rotate(0,90,0);
1011 weapons.throwingknifemodel.flat=0;
1012 weapons.throwingknifemodel.CalculateNormals(1);
1013 //weapons.throwingknifemodel.ScaleNormals(-1,-1,-1);
1015 weapons.swordmodel.load((char *)":Data:Models:sword.solid",1);
1016 weapons.swordmodel.Scale(.001,.001,.001);
1017 //weapons.swordmodel.Rotate(0,0,-90);
1018 weapons.swordmodel.Rotate(90,0,0);
1019 weapons.swordmodel.Rotate(0,90,0);
1020 weapons.swordmodel.Rotate(0,0,90);
1021 weapons.swordmodel.flat=1;
1022 weapons.swordmodel.CalculateNormals(1);
1023 //weapons.swordmodel.ScaleNormals(-1,-1,-1);
1025 weapons.staffmodel.load((char *)":Data:Models:staff.solid",1);
1026 weapons.staffmodel.Scale(.005,.005,.005);
1027 //weapons.staffmodel.Rotate(0,0,-90);
1028 weapons.staffmodel.Rotate(90,0,0);
1029 weapons.staffmodel.Rotate(0,90,0);
1030 weapons.staffmodel.Rotate(0,0,90);
1031 weapons.staffmodel.flat=1;
1032 weapons.staffmodel.CalculateNormals(1);
1033 //weapons.staffmodel.ScaleNormals(-1,-1,-1);
1035 //temptexdetail=texdetail;
1036 //if(texdetail>4)texdetail=4;
1037 LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
1039 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
1041 LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
1043 LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
1046 LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
1048 LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
1050 /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
1052 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
1054 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
1056 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
1058 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
1060 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
1061 //texdetail=temptexdetail;
1062 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
1066 LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
1068 LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
1071 //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
1074 LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
1075 LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
1076 LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
1077 LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
1078 LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
1079 LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
1080 LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
1081 LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
1082 LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
1083 LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
1084 LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
1088 ReSizeGLScene(90,.01);
1095 if(detail)kTextureSize=1024;
1096 if(detail==1)kTextureSize=512;
1097 if(detail==0)kTextureSize=256;
1100 //drawmode=motionblurmode;
1102 //Set up distant light
1106 light.ambient[0]=.2;
1107 light.ambient[1]=.2;
1108 light.ambient[2]=.24;
1111 light.location.z=-.2;
1112 Normalise(&light.location);
1122 texscale=.2/megascale/viewdistdetail;
1123 terrain.scale=3*megascale*terraindetail*viewdistdetail;
1125 viewer.x=terrain.size/2*terrain.scale;
1126 viewer.z=terrain.size/2*terrain.scale;
1128 hawk.load((char *)":Data:Models:hawk.solid",1);
1129 hawk.Scale(.03,.03,.03);
1130 hawk.Rotate(90,1,1);
1131 hawk.CalculateNormals(0);
1132 hawk.ScaleNormals(-1,-1,-1);
1133 hawkcoords.x=terrain.size/2*terrain.scale-5-7;
1134 hawkcoords.z=terrain.size/2*terrain.scale-5-7;
1135 hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
1138 eye.load((char *)":Data:Models:eye.solid",1);
1139 eye.Scale(.03,.03,.03);
1140 eye.CalculateNormals(0);
1142 cornea.load((char *)":Data:Models:cornea.solid",1);
1143 cornea.Scale(.03,.03,.03);
1144 cornea.CalculateNormals(0);
1146 iris.load((char *)":Data:Models:iris.solid",1);
1147 iris.Scale(.03,.03,.03);
1148 iris.CalculateNormals(0);
1150 LoadSave(":Data:Textures:Bloodfur.png",0,1,&bloodText[0],0);
1151 LoadSave(":Data:Textures:Wolfbloodfur.png",0,1,&wolfbloodText[0],0);
1159 //if(targetlevel!=7)
1160 Loadlevel(targetlevel);
1163 rabbitcoords=player[0].coords;
1164 rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
1166 loadAllAnimations();
1167 //Fix knife stab, too lazy to do it manually
1171 for(i=0;i<player[0].skeleton.num_joints;i++){
1172 for(j=0;j<animation[knifesneakattackanim].numframes;j++){
1173 animation[knifesneakattackanim].position[i][j]+=moveamount;
1180 for(i=0;i<player[0].skeleton.num_joints;i++){
1181 for(j=0;j<animation[knifesneakattackedanim].numframes;j++){
1182 animation[knifesneakattackedanim].position[i][j]+=moveamount;
1189 for(i=0;i<player[0].skeleton.num_joints;i++){
1190 animation[dead1anim].position[i][1]=animation[dead1anim].position[i][0];
1191 animation[dead2anim].position[i][1]=animation[dead2anim].position[i][0];
1192 animation[dead3anim].position[i][1]=animation[dead3anim].position[i][0];
1193 animation[dead4anim].position[i][1]=animation[dead4anim].position[i][0];
1195 animation[dead1anim].speed[0]=0.001;
1196 animation[dead2anim].speed[0]=0.001;
1197 animation[dead3anim].speed[0]=0.001;
1198 animation[dead4anim].speed[0]=0.001;
1200 animation[dead1anim].speed[1]=0.001;
1201 animation[dead2anim].speed[1]=0.001;
1202 animation[dead3anim].speed[1]=0.001;
1203 animation[dead4anim].speed[1]=0.001;
1205 for(i=0;i<player[0].skeleton.num_joints;i++){
1206 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1207 animation[swordsneakattackanim].position[i][j]+=moveamount;
1212 for(j=0;j<animation[swordsneakattackanim].numframes;j++){
1213 animation[swordsneakattackanim].weapontarget[j]+=moveamount;
1219 for(i=0;i<player[0].skeleton.num_joints;i++){
1220 for(j=0;j<animation[swordsneakattackedanim].numframes;j++){
1221 animation[swordsneakattackedanim].position[i][j]+=moveamount;
1225 for(i=0;i<player[0].skeleton.num_joints;i++){
1226 for(j=0;j<animation[sleepanim].numframes;j++){
1227 animation[sleepanim].position[i][j]=DoRotation(animation[sleepanim].position[i][j],0,180,0);
1233 temptexdetail=texdetail;
1235 texdetail=temptexdetail;
1242 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
1244 glGenTextures( 1, &screentexture );
1245 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
1248 glEnable(GL_TEXTURE_2D);
1249 glBindTexture( GL_TEXTURE_2D, screentexture);
1250 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
1251 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
1253 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0);
1257 emit_sound_at(fireendsound);