📄 newplayer.cpp
字号:
/*************************************************************************/
/* File : NewPlayer.cpp */
/* */
/* Last Modification : 22/04/2003 */
/* */
/* - The player now use a CWinApp object to be linked with the MFC */
/* this assures that the correct version of LoadLibrary is used and */
/* so avoids the pop-up error when plugins can not be loaded (DirectX */
/* rasterizer on NT for example) */
/* - a bool "quit" level attribute can be used to exit the player */
/* */
/* Virtools SDK */
/* Copyright (c) Virtools 2001, All Rights Reserved. */
/*************************************************************************/
#include "stdafx.h"
#include "NewPlayer.h"
#ifdef CK_LIB
#include "CKLibIncludes.h"
#include "NewPlayerStaticLibs.h"
#endif
#define MAX_LOADSTRING 100
#define BTN_PLAY 1
#define BTN_RESET 2
#define BTN_CLOSE 3
#define BTN_LOAD 4
#define MAXOPTIONS 9
#define CAPTIONHEIGHT 22
// Global Variables for Interface
HINSTANCE hInst; // current instance
HACCEL g_hAccelTable;
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The Main Window class Name
TCHAR szRenderWindowClass[MAX_LOADSTRING]; // The render window class Name
HWND g_MainWindow,g_RenderWin; // The Main Window and Render Window Handles
HMENU g_ContextMenu; // Contextual Menu
HBITMAP g_Plays[4]; // Menu Bitmaps
HBITMAP g_Reset[3]; // ...
HBITMAP g_Close[2]; // ...
HBITMAP g_Load[3]; // ...
HBITMAP g_Virtools; // ...
int g_CurrentPlayState=0; // Menu Button States...
int g_CurrentResetState=0; // ...
int g_CurrentCloseState=0; // ...
int g_CurrentLoadState=0; // ...
BOOL g_DisableSwitch=FALSE; // Disables switching to or from fullscreen mode
BOOL g_NoContextMenu=FALSE; // Disables the context menu on right clicks
BOOL g_GoFullScreen=FALSE; // Go directly to fullscreen
int g_RefreshRate=0; // Default Fullscreen refresh rate
int g_Width=640; // Default Window width
int g_Height=480; // Default Window Height
int g_Bpp=16; // Default FullScreen Bit Per Pixel
int g_Driver=0; // Default FullScreen Driver
int g_CaptionOffset=0;
RECT g_mainwin_rect; //size of the main window (used to resize it when switching to fullscreen
//------------------------------------------------
// Global Variables for Player
CKContext* TheCKContext=NULL;
CKTimeManager* TheTimeManager=NULL;
CKMessageManager* TheMessageManager=NULL;
CKRenderManager* TheRenderManager=NULL;
CKRenderContext* TheRenderContext=NULL;
CKSpriteText* TheFrameRate=NULL;
CKSpriteText* g_MadeWith=NULL;
BOOL g_ShowFrameRate=FALSE;
BOOL g_ShowMadeWith=FALSE; // Go directly to fullscreen
DWORD g_TimeToHideSprite=0;
int g_FullScreenDriver=0;
int g_Mode=-1;
int g_MsgClick,g_MsgDoubleClick;
CKParameterOut* g_po; //Attribute used for exiting and changing file
BOOL g_ExitCK=FALSE; //Attribute value for exiting the player
int g_attr=-1; //Attribute type used for exiting and changing file
CKLevel* g_Level;
//--------------------------------------------------
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Setup(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
void DoVirtoolsProcess();
void CreateInterfaceSprite();
BOOL Load(char *str) ;
int GetTitleBtn();
void RepaintTitleBar();
void OnFullScreen(BOOL Replay = TRUE);
void OnPlayPause(int force);
void OnReset();
void ExitVirtoolsPlayer();
#define FORCE_PLAY 1
#define FORCE_PAUSE 2
/////////////////////////////////////////////////////////////////////////////
// CNewPlayerApp
BEGIN_MESSAGE_MAP(CNewPlayerApp, CWinApp)
//{{AFX_MSG_MAP(CNewPlayerApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewPlayerApp construction
CNewPlayerApp::CNewPlayerApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CNewPlayerApp object
CNewPlayerApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CNewPlayerApp initialization
BOOL CNewPlayerApp::InitInstance()
{
// Initialize global strings
LoadString(m_hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(m_hInstance, IDC_NEWPLAYER, szWindowClass, MAX_LOADSTRING);
LoadString(m_hInstance, IDC_NEWPLAYERRENDER, szRenderWindowClass, MAX_LOADSTRING);
// Register window classes
MyRegisterClass(m_hInstance);
// Perform application initialization:
g_hAccelTable = LoadAccelerators(m_hInstance, (LPCTSTR)IDC_NEWPLAYER);
char Dummy[512]="";
char FileName[512]="";
char Options[MAXOPTIONS][128]={"","","","","","","",""};
char Engine[128]="CK2_3D"; // Default render engine
//----------------------
// Parse Command Line
// syntax Player File.cmo [[-Fullscreen] [-VideoDriver=0] [-Bpp=16]] [-W=640] [-H=480] [-R=60Hz] [-DisableSwitch] [-NoMenu]
XString lpCmdLine = GetCommandLine();
lpCmdLine.ToLower();
sscanf(lpCmdLine.Str(),"""%s"" %s -%s -%s -%s -%s -%s -%s -%s",Dummy,FileName,Options[0],Options[1],Options[2],Options[3],
Options[4],Options[5],Options[6],Options[7],Options[8]);
for (int i=0;i<MAXOPTIONS;i++) {
switch (Options[i][0])
{
case 'f': g_GoFullScreen=TRUE; g_DisableSwitch=TRUE; break;
case 'd': g_DisableSwitch=TRUE; break;
case 'n': g_NoContextMenu=TRUE; break;
case 'r': sscanf(Options[i],"r=%d",&g_RefreshRate); break;
case 'w': sscanf(Options[i],"w=%d",&g_Width); break;
case 'h': sscanf(Options[i],"h=%d",&g_Height); break;
case 'b': sscanf(Options[i],"bpp=%d",&g_Bpp); break;
case 'e': sscanf(Options[i],"engine=%s",Engine); break;
case 'v': sscanf(Options[i],"videodriver=%d",&g_Driver); break;
}
}
int Xpos,Ypos;
int Width=g_Width+GetSystemMetrics(SM_CXBORDER)*2,Height=g_Height+GetSystemMetrics(SM_CYBORDER)*3+CAPTIONHEIGHT;
//GetSystemMetrics(SM_CYCAPTION);
RECT rect,dev={0,0,g_Width,g_Height};
hInst = m_hInstance; // Store instance handle in our global variable
//--------- Splash dialog
HWND splash=CreateDialog(m_hInstance,(LPCTSTR)IDD_DIALOG2, NULL, (DLGPROC)About);
GetWindowRect(splash,&rect);
SetWindowPos(splash,NULL,(GetSystemMetrics(SM_CXSCREEN)-(rect.right-rect.left))/2,
(GetSystemMetrics(SM_CYSCREEN)-(rect.bottom-rect.top))/2,
0,0,SWP_NOZORDER|SWP_NOSIZE);
ShowWindow(splash, SW_SHOW);
UpdateWindow(splash);
g_CaptionOffset=CAPTIONHEIGHT-GetSystemMetrics(SM_CYCAPTION)-2*GetSystemMetrics(SM_CYBORDER);
//----------- Main Window Creation
Xpos=(GetSystemMetrics(SM_CXSCREEN)-Width)/2;
Ypos=(GetSystemMetrics(SM_CYSCREEN)-Height)/2;
g_MainWindow = CreateWindow(szWindowClass, szTitle,
WS_OVERLAPPEDWINDOW & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SYSMENU),
Xpos, Ypos, Width, Height,
NULL, NULL, m_hInstance, NULL);
if (!g_MainWindow) return FALSE;
//----------- Render Window Creation
g_RenderWin = CreateWindowEx(WS_EX_TOPMOST,szRenderWindowClass, "",
(WS_CHILD|WS_OVERLAPPED|WS_VISIBLE) & ~WS_CAPTION,0,g_CaptionOffset,g_Width,g_Height,g_MainWindow,NULL,m_hInstance,0);
if (!g_RenderWin) return FALSE;
DragAcceptFiles(g_MainWindow,TRUE);
DragAcceptFiles(g_RenderWin,TRUE);
int RenderEngine=0;
CKStartUp();
CKPluginManager* ThePluginManager=CKGetPluginManager();
#ifdef CK_LIB
/*******************************************************
Version of the player with every plugins included
as a static library and not a Dll
********************************************************/
//---- DX7 rasterizer...
ThePluginManager->AddRenderEngineRasterizer(CKDX8RasterizerGetInfo);
//---- 1: If every plugins are needed (need to compile with every lib)
/*
RegisterAllStaticPlugins(ThePluginManager);
*/
//---- 2 : The above is equivalent to :
/*
RegisterRenderEngine(ThePluginManager);
RegisterAllReaders(ThePluginManager);
RegisterAllManagers(ThePluginManager);
RegisterAllBehaviors(ThePluginManager);
*/
//---- 3 : The above is equivalent to :
//---- in this case we can get rid of plugins
//---- we know we will not need...
CKPluginManager* pm = ThePluginManager;
RegisterRenderEngine(pm);
RegisterVirtoolsReader(pm);
RegisterImageReader(pm);
RegisterAVIReader(pm);
RegisterPNGReader(pm);
RegisterJPGReader(pm);
RegisterMP3Reader(pm);
RegisterWAVReader(pm);
RegisterParamOpManager(pm);
RegisterInputManager(pm);
RegisterSoundManager(pm);
Register3DTransfoBehaviors(pm);
RegisterBBAddonsBehaviors(pm);
RegisterBBAddons2Behaviors(pm);
RegisterCamerasBehaviors(pm);
RegisterCamerasBehaviors(pm);
RegisterControllersBehaviors(pm);
RegisterCharactersBehaviors(pm);
RegisterCollisionsBehaviors(pm);
RegisterGridsBehaviors(pm);
RegisterInterfaceBehaviors(pm);
RegisterLightsBehaviors(pm);
RegisterLogicsBehaviors(pm);
RegisterMaterialsBehaviors(pm);
RegisterMeshesBehaviors(pm);
RegisterMidiBehaviors(pm);
RegisterNarrativesBehaviors(pm);
RegisterParticleSystemsBehaviors(pm);
//RegisterPhysicsBehaviors(pm);
RegisterSoundsBehaviors(pm);
RegisterVisualsBehaviors(pm);
RegisterWorldEnvBehaviors(pm);
RegisterVSLBehaviors(pm);
#else
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char szPath[_MAX_PATH],PluginPath[_MAX_PATH],RenderPath[_MAX_PATH],BehaviorPath[_MAX_PATH],ManagerPath[_MAX_PATH];
//--------- Get Extensions Directory
GetModuleFileName(NULL,szPath,_MAX_PATH);
_splitpath(szPath, drive, dir, NULL, NULL );
sprintf(PluginPath,"%s%s%s",drive,dir,"Plugins");
sprintf(RenderPath,"%s%s%s",drive,dir,"RenderEngines");
sprintf(ManagerPath,"%s%s%s",drive,dir,"Managers");
sprintf(BehaviorPath,"%s%s%s",drive,dir,"BuildingBlocks");
//--------- Parse Dlls
ThePluginManager->ParsePlugins(RenderPath);
ThePluginManager->ParsePlugins(ManagerPath);
ThePluginManager->ParsePlugins(BehaviorPath);
ThePluginManager->ParsePlugins(PluginPath);
//----- Search if a render engine was specified
int count=ThePluginManager->GetPluginCount(CKPLUGIN_RENDERENGINE_DLL);
if (strlen(Engine)>0) {
for (int i=0;i<count;i++)
{
CKPluginEntry* desc=ThePluginManager->GetPluginInfo(CKPLUGIN_RENDERENGINE_DLL,i);
CKPluginDll* dll =ThePluginManager->GetPluginDllInfo(desc->m_PluginDllIndex);
if (!strnicmp(Engine,dll->m_DllFileName.Str(),strlen(dll->m_DllFileName.Str()))) { RenderEngine=i; break; }
}
}
if (!count) {
MessageBox(NULL,"Initialisation Error","Unable to load a RenderEngine",MB_OK|MB_ICONERROR);
return FALSE;
}
#endif
XString inifile = CKGetStartPath();
inifile << "Player.ini";
//------ Initialize CK engine
CKERROR res=CKCreateContext(&TheCKContext,g_MainWindow,inifile.CStr());
if (res!=CK_OK)
{
if (res==CKERR_NODLLFOUND) MessageBox(NULL,"Initialisation Error","Unable to load a RenderEngine",MB_OK|MB_ICONERROR);
return FALSE;
}
TheCKContext->SetVirtoolsVersion(CK_VIRTOOLS_DEV,0x02000043);
TheMessageManager =TheCKContext->GetMessageManager();
TheTimeManager =TheCKContext->GetTimeManager();
TheRenderManager =TheCKContext->GetRenderManager();
//-------- Init Done => check available Display Mode and validate width / height / bpp settings
{
int i;
VxDriverDesc *MainDesc=TheRenderManager->GetRenderDriverDescription(0);
if (!MainDesc) {
MessageBox(NULL,"Initialisation Error","Unable to initialize a render driver",MB_OK|MB_ICONERROR);
CKCloseContext(TheCKContext);
return FALSE;
}
for (i=0;i<MainDesc->DisplayModes.Size();i++)
{
if (MainDesc->DisplayModes[i].Width==g_Width)
if (MainDesc->DisplayModes[i].Height==g_Height)
if (g_Bpp==MainDesc->DisplayModes[i].Bpp)
if (!g_RefreshRate || (g_RefreshRate == MainDesc->DisplayModes[i].RefreshRate)) {
g_FullScreenDriver=0;
g_Mode=i;
break;
}
}
if (g_Mode<0) {
// We didn't find a valid resolution try again with a different bpp (but > 16)
// default to a standard resolution
g_Width=640;
g_Height=480;
for (i=0;i<MainDesc->DisplayModes.Size();i++)
{
if (MainDesc->DisplayModes[i].Width==g_Width)
if (MainDesc->DisplayModes[i].Height==g_Height)
if (MainDesc->DisplayModes[i].Bpp>8) {
g_FullScreenDriver=0;
g_Mode=i;
g_Bpp=MainDesc->DisplayModes[i].Bpp;
break;
}
}
}
}
//---- If current driver cannot do windowed mode force fullscreen
// VxDriverDesc* desc=CKGetRenderDriverDescription(g_Driver);
// if (!desc->Caps2D.CanDoWindowed) g_GoFullScreen=TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -