29 |
#include "system.hh" |
#include "system.hh" |
30 |
#include "gui.hh" |
#include "gui.hh" |
31 |
#include "menus.hh" |
#include "menus.hh" |
32 |
|
#include "oxyd.hh" |
33 |
|
|
34 |
#include "game.hh" |
#include "game.hh" |
35 |
|
|
36 |
#include "px/sdl.hh" |
#include "px/sdl.hh" |
37 |
|
#include "px/argp.hh" |
38 |
|
|
39 |
#include <algorithm> |
#include <algorithm> |
40 |
#include <fstream> |
#include <fstream> |
41 |
|
#include <iostream> |
|
#ifndef __APPLE__ |
|
|
#include "getopt.h" |
|
|
#endif |
|
42 |
|
|
43 |
using namespace std; |
using namespace std; |
44 |
using namespace px; |
using namespace px; |
116 |
class FontAlloc { |
class FontAlloc { |
117 |
public: |
public: |
118 |
Font *acquire(const std::string &name) { |
Font *acquire(const std::string &name) { |
119 |
string fname = enigma::FindDataFile(string("fonts/") + name + ".png"); |
string fname = enigma::FindDataFile(string("fonts/")+name+".png"); |
120 |
string dname = enigma::FindDataFile(string("fonts/") + name + ".bmf"); |
string dname = enigma::FindDataFile(string("fonts/")+name+".bmf"); |
121 |
return px::LoadBitmapFont(fname.c_str(), dname.c_str()); |
return px::LoadBitmapFont(fname.c_str(), dname.c_str()); |
122 |
} |
} |
123 |
void release(Font *f) { delete f; } |
void release(Font *f) { delete f; } |
163 |
vector<LevelPack *> LevelPacks; |
vector<LevelPack *> LevelPacks; |
164 |
|
|
165 |
Application app; |
Application app; |
166 |
|
|
167 |
} |
} |
168 |
|
|
169 |
|
|
170 |
|
/* The stream object that is used for logging messages. As defined |
171 |
|
here, it is not connected to any file or buffer. */ |
172 |
|
std::ostream enigma::Log(0); |
173 |
|
|
174 |
|
/* This is the stream object that is used when logging to a file. In |
175 |
|
this case, enigma::Log uses this object's streambuffer. */ |
176 |
|
static std::fstream logfile; |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
//====================================================================== |
//====================================================================== |
181 |
// MAIN PROGRAM |
// MAIN PROGRAM |
407 |
dtime = 0.0; |
dtime = 0.0; |
408 |
else if (dtime > 0.5) |
else if (dtime > 0.5) |
409 |
dtime = 0.5; |
dtime = 0.5; |
|
// if (dtime > 15.0/1000) |
|
|
// dtime = 15.0/1000; |
|
410 |
} |
} |
411 |
video::ShowMouse(); |
video::ShowMouse(); |
412 |
} |
} |
487 |
} |
} |
488 |
} |
} |
489 |
|
|
|
static void set_mousedamping(double d) |
|
|
{ |
|
|
if (d > 0 && d < 100) { |
|
|
// display::StatusBar *sb = display::GetStatusBar(); |
|
|
// char msg[200]; |
|
|
// options::MouseDamping = int(d); |
|
|
// sprintf(msg, "Mouse damping: %d", int(d)); |
|
|
// sb->show_text(msg, display::TEXT_2SECONDS); |
|
|
} |
|
|
} |
|
|
|
|
490 |
static void set_frictionfactor(double f) |
static void set_frictionfactor(double f) |
491 |
{ |
{ |
492 |
if (f > 0 && f < 10) { |
if (f > 0 && f < 10) { |
509 |
|
|
510 |
case SDLK_LEFT: set_mousespeed(options::MouseSpeed - 1); break; |
case SDLK_LEFT: set_mousespeed(options::MouseSpeed - 1); break; |
511 |
case SDLK_RIGHT: set_mousespeed(options::MouseSpeed + 1); break; |
case SDLK_RIGHT: set_mousespeed(options::MouseSpeed + 1); break; |
|
case SDLK_UP: set_mousedamping(options::MouseDamping + 2); break; |
|
|
case SDLK_DOWN: set_mousedamping(options::MouseDamping - 2); break; |
|
512 |
case SDLK_PAGEUP: |
case SDLK_PAGEUP: |
513 |
set_frictionfactor (options::FrictionFactor+0.5); |
set_frictionfactor (options::FrictionFactor+0.5); |
514 |
break; |
break; |
657 |
datapaths.set_path(p); |
datapaths.set_path(p); |
658 |
} |
} |
659 |
|
|
660 |
|
bool |
661 |
|
enigma::FindFile (const string &fname, string &dst_fname) |
662 |
|
{ |
663 |
|
return datapaths.find_file(fname, dst_fname); |
664 |
|
} |
665 |
|
|
666 |
string |
string |
667 |
enigma::FindDataFile(const string &filename) |
enigma::FindDataFile(const string &filename) |
668 |
{ |
{ |
747 |
fprintf(stderr, "Error in configuration file.\n"); |
fprintf(stderr, "Error in configuration file.\n"); |
748 |
} |
} |
749 |
|
|
750 |
// Evaluate command line arguments |
/* |
751 |
bool nosound_flag = false; |
** Evaluate command line arguments. |
752 |
bool nomusic_flag = false; |
*/ |
753 |
bool show_help = false; |
struct AP : public argp::ArgParser { |
754 |
bool show_version = false; |
public: |
755 |
for (unsigned i=0; i < app.args.size(); ++i) |
enum { |
756 |
{ |
OPT_NOSOUND, OPT_NOMUSIC, OPT_VERSION, OPT_HELP, |
757 |
string& arg = app.args[i]; |
OPT_WINDOW, OPT_WIZARD, OPT_NOGRAB, OPT_LOG, |
758 |
|
OPT_8BPP, OPT_GAME, |
759 |
|
OPT_PEROXYD, OPT_OXYD1, OPT_EXTRA, OPT_MAGNUM |
760 |
|
}; |
761 |
|
|
762 |
if (arg == "--help" || arg == "-h") |
AP() : ArgParser (app.args.begin(), app.args.end()) |
763 |
|
{ |
764 |
|
nosound = nomusic = show_help = show_version = do_log = false; |
765 |
|
gamename = ""; |
766 |
|
gametype = GAMET_ENIGMA; |
767 |
|
|
768 |
|
def (OPT_NOSOUND, 0, "nosound"); |
769 |
|
def (OPT_NOMUSIC, 0, "nomusic"); |
770 |
|
def (OPT_VERSION, 0, "version"); |
771 |
|
def (OPT_HELP, 'h', "help"); |
772 |
|
def (OPT_WINDOW, 'w', "window"); |
773 |
|
def (OPT_WIZARD, 0, "wizard"); |
774 |
|
def (OPT_NOGRAB, 0, "nograb"); |
775 |
|
def (OPT_LOG, 'l', "log"); |
776 |
|
def (OPT_8BPP, '8', "8bpp"); |
777 |
|
def (OPT_GAME, 'g', "game", true); |
778 |
|
def (OPT_PEROXYD, 0, "peroxyd"); |
779 |
|
def (OPT_OXYD1, 0, "oxyd1"); |
780 |
|
def (OPT_EXTRA, 0, "oxydextra"); |
781 |
|
def (OPT_MAGNUM,0, "oxydmagnum"); |
782 |
|
} |
783 |
|
|
784 |
|
// ArgParser interface. |
785 |
|
void on_error (ErrorType t, const string &option) { |
786 |
|
cout << errormsg(t, option) << endl; |
787 |
show_help = true; |
show_help = true; |
788 |
else if (arg == "--nosound") |
} |
789 |
nosound_flag = true; |
|
790 |
else if (arg == "--nomusic") |
void on_option (int id, const string ¶m) { |
791 |
nomusic_flag = true; |
switch (id) { |
792 |
else if (arg == "--version") |
case OPT_NOSOUND: nosound=true; break; |
793 |
show_version = true; |
case OPT_NOMUSIC: nomusic=true; break; |
794 |
else if (arg == "--window") |
case OPT_VERSION: show_version=true; break; |
795 |
options::FullScreen = false; |
case OPT_HELP: show_help=true; break; |
796 |
else if (arg == "--wizard") |
case OPT_WINDOW: options::FullScreen=false; break; |
797 |
options::WizardMode = true; |
case OPT_WIZARD: options::WizardMode=true; break; |
798 |
else if (arg == "--8bpp") |
case OPT_NOGRAB: options::Nograb=true; break; |
799 |
options::BitsPerPixel = 8; |
case OPT_8BPP: options::BitsPerPixel = 8; break; |
800 |
else if (arg == "--nograb") |
case OPT_GAME: gamename = param; break; |
801 |
options::Nograb = true; |
case OPT_LOG: do_log = true; break; |
802 |
else |
case OPT_PEROXYD: gametype = GAMET_PEROXYD; break; |
803 |
show_help = true; // unknown argument |
case OPT_OXYD1: gametype = GAMET_OXYD1; break; |
804 |
} |
case OPT_EXTRA: gametype = GAMET_OXYDEXTRA; break; |
805 |
if (show_help || show_version) { |
case OPT_MAGNUM: gametype = GAMET_OXYDMAGNUM; break; |
806 |
|
} |
807 |
|
} |
808 |
|
|
809 |
|
void on_argument (const string &arg) { |
810 |
|
} |
811 |
|
|
812 |
|
// Variables. |
813 |
|
bool nosound, nomusic, show_help, show_version, do_log; |
814 |
|
string gamename; |
815 |
|
GameType gametype; |
816 |
|
}; |
817 |
|
AP ap; |
818 |
|
ap.parse(); |
819 |
|
|
820 |
|
if (ap.show_help || ap.show_version) { |
821 |
printf("Enigma v%s\n",VERSION); |
printf("Enigma v%s\n",VERSION); |
822 |
if (show_help) usage(); |
if (ap.show_help) usage(); |
823 |
exit(0); |
exit(0); |
824 |
} |
} |
825 |
|
|
826 |
|
if (ap.do_log) { |
827 |
|
logfile.open("enigma.log", ios::out); |
828 |
|
if (logfile) |
829 |
|
enigma::Log.rdbuf(logfile.rdbuf()); |
830 |
|
else |
831 |
|
fprintf(stderr,"Could not open log file \"enigma.log\" for writing.\n"); |
832 |
|
} |
833 |
|
|
834 |
int sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; |
int sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; |
835 |
if (!nosound_flag) |
if (!ap.nosound) |
836 |
sdl_flags |= SDL_INIT_AUDIO; |
sdl_flags |= SDL_INIT_AUDIO; |
837 |
|
|
838 |
if (SDL_Init(sdl_flags) < 0) { |
if (SDL_Init(sdl_flags) < 0) { |
840 |
exit(1); |
exit(1); |
841 |
} |
} |
842 |
|
|
843 |
if (nosound_flag) |
if (ap.nosound) |
844 |
sound::DisableSound(); |
sound::DisableSound(); |
845 |
else if (nomusic_flag) |
else if (ap.nomusic) |
846 |
sound::DisableMusic(); |
sound::DisableMusic(); |
847 |
|
|
848 |
|
if (ap.gamename == "enigma") { |
849 |
|
oxyd::Init(); |
850 |
|
} |
851 |
video::Init(); |
video::Init(); |
852 |
video::SetPalette("enigma.pal"); |
video::SetPalette("enigma.pal"); |
853 |
display::Init(); |
display::Init(); |