2013-07-03 17:50:40 -05:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
*
* This program 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 . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
*/
# include "common/scummsys.h"
# include "common/config-manager.h"
# include "common/debug.h"
# include "common/debug-channels.h"
2013-07-06 01:52:45 -05:00
# include "common/textconsole.h"
2013-07-03 17:50:40 -05:00
# include "common/error.h"
# include "common/system.h"
# include "common/file.h"
# include "engines/util.h"
2013-08-04 23:10:27 -05:00
# include "audio/mixer.h"
2013-07-03 17:50:40 -05:00
# include "zvision/zvision.h"
2013-07-06 01:52:45 -05:00
# include "zvision/console.h"
2013-07-03 17:50:40 -05:00
# include "zvision/script_manager.h"
2013-07-19 11:07:58 -05:00
# include "zvision/render_manager.h"
2013-08-04 23:10:27 -05:00
# include "zvision/clock.h"
2013-07-03 17:50:40 -05:00
# include "zvision/zfs_archive.h"
2013-07-16 16:52:46 -05:00
# include "zvision/detection.h"
2013-07-03 17:50:40 -05:00
2013-07-06 00:26:01 -05:00
# include "zvision/utility.h"
2013-07-03 17:50:40 -05:00
namespace ZVision {
2013-07-08 16:04:18 -05:00
ZVision : : ZVision ( OSystem * syst , const ZVisionGameDescription * gameDesc )
: Engine ( syst ) ,
_gameDescription ( gameDesc ) ,
_width ( 640 ) ,
2013-08-04 23:10:27 -05:00
_height ( 480 ) ,
_pixelFormat ( 2 , 5 , 5 , 5 , 0 , 10 , 5 , 0 , 0 ) , /*RGB 555*/
2013-08-04 23:54:53 -05:00
_desiredFrameTime ( 33 ) , /* ~30 fps */
_clock ( _system ) {
2013-07-03 17:50:40 -05:00
// Put your engine in a sane state, but do nothing big yet;
// in particular, do not load data from files; rather, if you
// need to do such things, do them from run().
// Do not initialize graphics here
// However this is the place to specify all default directories
const Common : : FSNode gameDataDir ( ConfMan . get ( " path " ) ) ;
2013-07-24 11:39:54 -05:00
// TODO: There are 10 file clashes when we flatten the directories. From a quick look, the files are exactly the same, so it shouldn't matter. But I'm noting it here just in-case it does become a problem.
SearchMan . addSubDirectoryMatching ( gameDataDir , " data1 " , 0 , 4 , true ) ;
SearchMan . addSubDirectoryMatching ( gameDataDir , " data2 " , 0 , 4 , true ) ;
SearchMan . addSubDirectoryMatching ( gameDataDir , " data3 " , 0 , 4 , true ) ;
2013-07-30 12:56:21 +03:00
SearchMan . addSubDirectoryMatching ( gameDataDir , " zassets1 " , 0 , 2 , true ) ;
SearchMan . addSubDirectoryMatching ( gameDataDir , " zassets2 " , 0 , 2 , true ) ;
2013-07-24 11:39:54 -05:00
SearchMan . addSubDirectoryMatching ( gameDataDir , " znemmx " , 0 , 1 , true ) ;
2013-07-03 17:50:40 -05:00
// Here is the right place to set up the engine specific debug channels
//DebugMan.addDebugChannel(kZVisionDebugExample, "example", "this is just an example for a engine specific debug channel");
//DebugMan.addDebugChannel(kZVisionDebugExample2, "example2", "also an example");
// Register random source
_rnd = new Common : : RandomSource ( " zvision " ) ;
// Create managers
2013-07-11 00:26:32 -05:00
_scriptManager = new ScriptManager ( this ) ;
2013-07-20 12:14:32 -05:00
_renderManager = new RenderManager ( _system , _width , _height ) ;
2013-07-03 17:50:40 -05:00
debug ( " ZVision::ZVision " ) ;
}
2013-08-04 23:10:27 -05:00
2013-07-03 17:50:40 -05:00
ZVision : : ~ ZVision ( ) {
debug ( " ZVision::~ZVision " ) ;
// Dispose of resources
2013-07-06 01:52:45 -05:00
delete _console ;
2013-08-04 23:10:27 -05:00
delete _renderManager ;
2013-07-03 17:50:40 -05:00
delete _scriptManager ;
delete _rnd ;
// Remove all of our debug levels
DebugMan . clearAllDebugChannels ( ) ;
}
void ZVision : : initialize ( ) {
// Find zfs archive files
Common : : ArchiveMemberList list ;
SearchMan . listMatchingMembers ( list , " *.zfs " ) ;
// Register the file entries within the zfs archives with the SearchMan
for ( Common : : ArchiveMemberList : : iterator iter = list . begin ( ) ; iter ! = list . end ( ) ; + + iter ) {
Common : : String name = ( * iter ) - > getName ( ) ;
ZfsArchive * archive = new ZfsArchive ( name , ( * iter ) - > createReadStream ( ) ) ;
SearchMan . add ( name , archive ) ;
}
2013-08-04 23:10:27 -05:00
initGraphics ( _width , _height , true , & _pixelFormat ) ;
2013-07-03 17:50:40 -05:00
_scriptManager - > initialize ( ) ;
// Create debugger console. It requires GFX to be initialized
_console = new Console ( this ) ;
}
Common : : Error ZVision : : run ( ) {
initialize ( ) ;
// Main loop
while ( ! shouldQuit ( ) ) {
2013-08-04 23:54:53 -05:00
_clock . update ( ) ;
uint32 currentTime = _clock . getLastMeasuredTime ( ) ;
2013-07-03 17:50:40 -05:00
2013-08-04 23:10:27 -05:00
processEvents ( ) ;
2013-07-08 16:08:16 -05:00
2013-08-04 23:54:53 -05:00
_scriptManager - > updateNodes ( _clock . getDeltaTime ( ) ) ;
2013-07-24 11:33:58 -05:00
_scriptManager - > checkPuzzleCriteria ( ) ;
// Render a frame
_renderManager - > updateScreen ( _console - > isActive ( ) ) ;
2013-07-03 17:50:40 -05:00
2013-07-24 11:33:58 -05:00
// Calculate the frame delay based off a desired frame time
2013-08-04 23:10:27 -05:00
int delay = _desiredFrameTime - ( currentTime - _system - > getMillis ( ) ) ;
2013-07-03 17:50:40 -05:00
// Ensure non-negative
delay = delay < 0 ? 0 : delay ;
_system - > delayMillis ( delay ) ;
}
return Common : : kNoError ;
}
ScriptManager * ZVision : : getScriptManager ( ) const {
return _scriptManager ;
}
2013-07-19 11:07:58 -05:00
RenderManager * ZVision : : getRenderManager ( ) const {
return _renderManager ;
}
2013-07-03 17:50:40 -05:00
Common : : RandomSource * ZVision : : getRandomSource ( ) const {
return _rnd ;
}
2013-07-16 16:52:46 -05:00
ZVisionGameId ZVision : : getGameId ( ) const {
return _gameDescription - > gameId ;
2013-07-13 11:34:28 -05:00
}
2013-07-03 17:50:40 -05:00
} // End of namespace ZVision