scummvm/main.cpp

194 lines
4.6 KiB
C++
Raw Normal View History

2003-08-15 18:00:22 +00:00
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003-2004 The ScummVM-Residual Team (www.scummvm.org)
2003-08-15 18:00:22 +00:00
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "stdafx.h"
2003-08-15 18:00:22 +00:00
#include <SDL.h>
#include <SDL_video.h>
#include "bitmap.h"
#include "resource.h"
#include "debug.h"
#include "lua.h"
#include "registry.h"
#include "engine.h"
#include "sound.h"
2003-12-12 21:38:12 +00:00
#include "timer.h"
#include "smush.h"
#include "mixer/mixer.h"
2004-04-20 07:40:14 +00:00
#include "driver_gl.h"
#ifndef _MSC_VER
2003-08-15 18:00:22 +00:00
#include <unistd.h>
#endif
// Hacky global toggles for experimental/debug code
2004-04-15 20:20:04 +00:00
bool ZBUFFER_GLOBAL, SCREENBLOCKS_GLOBAL, SHOWFPS_GLOBAL;
2003-08-15 18:00:22 +00:00
static void saveRegistry() {
Registry::instance()->save();
2003-08-15 18:00:22 +00:00
}
#ifdef __MINGW32__
int PASCAL WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) {
return main(0, NULL);
}
#endif
extern SoundMixer *g_mixer;
2003-12-12 21:38:12 +00:00
extern Timer *g_timer;
static bool parseBoolStr(const char *val) {
if (val == NULL || val[0] == 0)
return false;
2004-04-20 07:40:14 +00:00
switch (val[0]) {
case 'y': case 'Y': // yes
case 't': case 'T': // true
case '1':
return true;
case 'n': case 'N': // no
case 'f': case 'F': // false
case '0':
return false;
case 'o':
switch (val[1]) {
case 'n': case 'N': // on
return true;
case 'f': case 'F': // off
return false;
}
}
2004-04-20 07:40:14 +00:00
error("Unrecognized boolean value %s\n", val);
2004-04-20 07:40:14 +00:00
return false;
}
int main(int argc, char *argv[]) {
int i;
// Parse command line
ZBUFFER_GLOBAL = parseBoolStr(Registry::instance()->get("zbuffer"));
SCREENBLOCKS_GLOBAL = parseBoolStr(Registry::instance()->get("screenblocks"));
SHOWFPS_GLOBAL = parseBoolStr(Registry::instance()->get("fps"));
2004-12-09 23:55:43 +00:00
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-zbuffer") == 0)
ZBUFFER_GLOBAL = true;
else if (strcmp(argv[i], "-nozbuffer") == 0)
ZBUFFER_GLOBAL = false;
else if (strcmp(argv[i], "-screenblocks") == 0)
SCREENBLOCKS_GLOBAL = true;
else if (strcmp(argv[i], "-noscreenblocks") == 0)
SCREENBLOCKS_GLOBAL = false;
2004-04-15 20:20:04 +00:00
else if (strcmp(argv[i], "-fps") == 0)
SHOWFPS_GLOBAL = true;
else if (strcmp(argv[i], "-nofps") == 0)
SHOWFPS_GLOBAL = false;
else {
printf("Residual CVS Version\n");
printf("--------------------\n");
printf("Recognised options:\n");
printf("\t-[no]zbuffer\t\tEnable/disable ZBuffers (Very slow on older cards)\n");
printf("\t-[no]screenblocks\t\tEnable/disable Screenblocks (Experimental zbuffer speedup on older cards - BROKEN!!\n");
2004-04-16 10:56:27 +00:00
printf("\t-[no]fps\t\tEnable/disable fps display in upper right corner\n");
exit(-1);
}
}
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
return 1;
2003-08-15 18:00:22 +00:00
atexit(SDL_Quit);
atexit(saveRegistry);
g_mixer = new SoundMixer();
g_timer = new Timer();
g_smush = new Smush();
g_driver = new Driver(640, 480, 24);
Mixer::instance()->start();
2003-08-15 18:00:22 +00:00
Bitmap *splash_bm = ResourceLoader::instance()->loadBitmap("splash.bm");
SDL_Event event;
// For some reason we don't get the SDL_VIDEOEXPOSE event on OSX, so just don't wait for it.
#ifndef MACOSX
while (SDL_PollEvent(&event)) {
if (event.type == SDL_VIDEOEXPOSE) {
#else
SDL_PollEvent(&event);
#endif
g_driver->clearScreen();
splash_bm->draw();
2003-08-15 18:00:22 +00:00
g_driver->flipBuffer();
#ifndef MACOSX
}
}
#endif
lua_iolibopen();
lua_strlibopen();
lua_mathlibopen();
2003-08-15 18:00:22 +00:00
register_lua();
bundle_dofile("_system.lua");
2003-08-15 18:00:22 +00:00
lua_pushnil(); // resumeSave
2004-10-31 09:37:06 +00:00
lua_pushnil(); // bootParam
// lua_pushnumber(0); // bootParam
lua_call("BOOT");
2003-08-15 18:00:22 +00:00
Engine::instance()->setMode(ENGINE_MODE_NORMAL);
Engine::instance()->mainLoop();
2003-08-15 18:00:22 +00:00
2004-11-01 18:49:48 +00:00
lua_close();
delete g_smush;
delete g_timer;
delete g_mixer;
return 0;
2003-08-15 18:00:22 +00:00
}
2003-12-12 21:38:12 +00:00
2004-12-09 23:55:43 +00:00
StackLock::StackLock(MutexRef mutex) :
_mutex(mutex) {
2003-12-12 21:38:12 +00:00
lock_mutex(_mutex);
}
StackLock::~StackLock() {
unlock_mutex(_mutex);
}
MutexRef create_mutex() {
2004-12-09 23:55:43 +00:00
return (MutexRef)SDL_CreateMutex();
2003-12-12 21:38:12 +00:00
}
void lock_mutex(MutexRef mutex) {
2004-12-09 23:55:43 +00:00
SDL_mutexP((SDL_mutex *)mutex);
2003-12-12 21:38:12 +00:00
}
void unlock_mutex(MutexRef mutex) {
2004-12-09 23:55:43 +00:00
SDL_mutexV((SDL_mutex *)mutex);
2003-12-12 21:38:12 +00:00
}
void delete_mutex(MutexRef mutex) {
2004-12-09 23:55:43 +00:00
SDL_DestroyMutex((SDL_mutex *)mutex);
2003-12-12 21:38:12 +00:00
}