port from perforce
This commit is contained in:
961
evoke-64k/ev09/main.cpp
Normal file
961
evoke-64k/ev09/main.cpp
Normal file
@@ -0,0 +1,961 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define VC_EXTRALEAN
|
||||
#define STRICT
|
||||
|
||||
//#define EXTRACODE
|
||||
#define STARTMUSIC
|
||||
//#define LOW_DETAIL
|
||||
|
||||
|
||||
#define CREATE_HEADER
|
||||
//#define KEYDATA_TRANSPOSE
|
||||
|
||||
//#define SINGLEEDITMODE
|
||||
//#define SCRIPTEDITOR
|
||||
|
||||
#ifdef STARTMUSIC
|
||||
#include "v2mplayer.h"
|
||||
#include "libv2.h"
|
||||
#include "song/songbin.h"
|
||||
|
||||
static V2MPlayer player;
|
||||
#endif
|
||||
|
||||
#define WindowTitle "CMath 4k Intro Wannabe"
|
||||
#define WindowClassName "CMath 4k Intro Wannabe"
|
||||
|
||||
int c_iScreenSizeX= 1024;
|
||||
int c_iScreenSizeY= 768;
|
||||
|
||||
//#define DISABLEAUTOSCREEN
|
||||
//#define DISABLEAUTOQUIT
|
||||
//#define WINDOWED
|
||||
//int c_iScreenSizeX= 1280;
|
||||
//int c_iScreenSizeY= 720;
|
||||
|
||||
//int c_iScreenSizeX= 1680;
|
||||
//int c_iScreenSizeY= 1050;
|
||||
|
||||
//#define WINDOWED
|
||||
//int c_iScreenSizeX= 1280;
|
||||
//int c_iScreenSizeY= 800;
|
||||
|
||||
int c_iRealScreenY= c_iScreenSizeY;
|
||||
|
||||
#ifdef WINDOWED
|
||||
bool bWindowed= true;
|
||||
#else
|
||||
bool bWindowed= false;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef LOW_DETAIL
|
||||
bool bLowDetail= true;
|
||||
#else
|
||||
bool bLowDetail= false;
|
||||
#endif
|
||||
|
||||
#include "intrin.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
#include <d3d9.h>
|
||||
#include <d3dx9math.h>
|
||||
|
||||
#undef WINAPI
|
||||
#define WINAPI __declspec(nothrow) __stdcall
|
||||
|
||||
|
||||
#ifdef LOW_DETAIL
|
||||
const int c_iTeselation= 8;
|
||||
#else
|
||||
const int c_iTeselation= 12 * 4;
|
||||
#endif
|
||||
|
||||
#ifdef EXTRACODE
|
||||
# ifdef SINGLEEDITMODE
|
||||
int g_iCurrentPortrait= 0;
|
||||
int g_iCurrentObject= 0;
|
||||
int g_iCurrentObjectCount= 0;
|
||||
int g_iCurrentCamera= 0;
|
||||
# endif
|
||||
# ifdef SCRIPTEDITOR
|
||||
int g_iSkipTicks= 0;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
////
|
||||
// CRT replacement functions
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//extern "C" int _fltused = 1;
|
||||
int __cdecl main(){return 0;};
|
||||
|
||||
|
||||
#undef ZeroMemory
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Globale Daten
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#pragma section("float",read,write)
|
||||
__declspec(allocate("float"))
|
||||
|
||||
LPDIRECT3D9 g_D3D;
|
||||
IDirect3DDevice9 *g_d3d_device;
|
||||
|
||||
D3DXMATRIX matView;
|
||||
|
||||
D3DXMATRIX d3dMatProj;
|
||||
|
||||
const D3DMATRIX d3dMatWorld=
|
||||
{
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 40.0f
|
||||
};
|
||||
|
||||
#ifndef STARTMUSIC
|
||||
DWORD g_dwTimeReplaceStart;
|
||||
#endif
|
||||
|
||||
int g_iTempo= ( 44100 * 60 * 8 ) / 140;
|
||||
const int g_iSampleOffsetGeneral= 2205;
|
||||
int g_iSampleOffset= g_iSampleOffsetGeneral;
|
||||
|
||||
int g_dwSamplesPassed= 0;
|
||||
int g_dwSamples= 0;
|
||||
|
||||
struct SVUMeter
|
||||
{
|
||||
const static int m_iBufferLength= 441;
|
||||
float m_fVUData[ m_iBufferLength ];
|
||||
int m_iLastPos;
|
||||
|
||||
SVUMeter()
|
||||
{
|
||||
m_iLastPos= 0;
|
||||
for( int i= 0; i < m_iBufferLength; ++i )
|
||||
{
|
||||
m_fVUData[ i ]= 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Set( int iPos,
|
||||
float fVal )
|
||||
{
|
||||
iPos= iPos % m_iBufferLength;
|
||||
while( true )
|
||||
{
|
||||
m_fVUData[ m_iLastPos ]= fVal;
|
||||
if( m_iLastPos != iPos )
|
||||
{
|
||||
m_iLastPos++;
|
||||
m_iLastPos= m_iLastPos % m_iBufferLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Get( int iPos )
|
||||
{
|
||||
iPos= iPos % m_iBufferLength;
|
||||
return m_fVUData[ iPos ];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
SVUMeter g_vuLightBeat;
|
||||
SVUMeter g_vuOffBeat;
|
||||
|
||||
struct ScriptState
|
||||
{
|
||||
int iTargetTick;
|
||||
int iScriptPointer;
|
||||
int iScriptParam;
|
||||
|
||||
float m_fCamSpeed;
|
||||
float m_fObjectSpeed;
|
||||
|
||||
float m_fCamTime;
|
||||
float m_fObjectTime;
|
||||
|
||||
int m_iCam;
|
||||
|
||||
int m_iObject;
|
||||
int m_iObjectCount;
|
||||
|
||||
int m_iPorPointer;
|
||||
int m_iPorStartTick;
|
||||
|
||||
void Prepare()
|
||||
{
|
||||
iTargetTick= 0;
|
||||
iScriptPointer= 0;
|
||||
iScriptParam= 0;
|
||||
|
||||
m_fCamSpeed= 1.0f;
|
||||
m_fObjectSpeed= 1.0f;
|
||||
|
||||
m_fCamTime= 0.0f;
|
||||
m_fObjectTime= 0.0f;
|
||||
|
||||
m_iCam= 0;
|
||||
|
||||
m_iObject= 0;
|
||||
m_iObjectCount= 1;
|
||||
|
||||
m_iPorPointer= 0;
|
||||
m_iPorStartTick= 0;
|
||||
}
|
||||
};
|
||||
|
||||
ScriptState g_ScriptState;
|
||||
|
||||
struct SVertex
|
||||
{
|
||||
FLOAT x, y, z;
|
||||
FLOAT nx, ny, nz;
|
||||
//DWORD dwColor?
|
||||
};
|
||||
|
||||
const DWORD c_dwFVF=D3DFVF_XYZ|D3DFVF_NORMAL;
|
||||
|
||||
|
||||
#pragma section("winarray",read,write)
|
||||
__declspec(allocate("winarray"))
|
||||
|
||||
D3DPRESENT_PARAMETERS d3dpp=
|
||||
{
|
||||
1024,//UINT BackBufferWidth;
|
||||
768,//UINT BackBufferHeight;
|
||||
D3DFMT_X8R8G8B8,//D3DFORMAT BackBufferFormat;
|
||||
2,//UINT BackBufferCount;
|
||||
|
||||
D3DMULTISAMPLE_16_SAMPLES,//D3DMULTISAMPLE_TYPE MultiSampleType;
|
||||
0,//DWORD MultiSampleQuality;
|
||||
|
||||
D3DSWAPEFFECT_DISCARD,//D3DSWAPEFFECT SwapEffect;
|
||||
0,//HWND hDeviceWindow;
|
||||
FALSE,//BOOL Windowed;
|
||||
TRUE,//BOOL EnableAutoDepthStencil;
|
||||
D3DFMT_D24S8,//D3DFORMAT AutoDepthStencilFormat;
|
||||
0,//DWORD Flags;
|
||||
|
||||
/* FullScreen_RefreshRateInHz must be zero for Windowed mode */
|
||||
0,//UINT FullScreen_RefreshRateInHz;
|
||||
D3DPRESENT_INTERVAL_IMMEDIATE, //UINT PresentationInterval;
|
||||
};
|
||||
|
||||
|
||||
IDirect3DTexture9* g_pPictures[ 32 ];
|
||||
|
||||
|
||||
#pragma section("float",read,write)
|
||||
__declspec(allocate("float"))
|
||||
|
||||
D3DLIGHT9 d3dLight[3]=
|
||||
{
|
||||
{
|
||||
D3DLIGHT_POINT,// D3DLIGHTTYPE Type; /* Type of light source */
|
||||
{ 1.0f, 1.0f, 0.85f, 0.0f },// D3DCOLORVALUE Diffuse; /* Diffuse color of light */
|
||||
{ 1.0f, 1.0f, 1.0f, 0.0f },// D3DCOLORVALUE Specular; /* Specular color of light */
|
||||
{ 0.0625f, 0.0625f, 0.0625f, 0.0f },// D3DCOLORVALUE Ambient; /* Ambient color of light */
|
||||
{ 48.0f, 96.0f, -48.0f },// D3DVECTOR Position; /* Position in world space */
|
||||
{ 0.0f, 0.0f, 0.0f },// D3DVECTOR Direction; /* Direction in world space */
|
||||
1024.0f, //float Range; /* Cutoff range */
|
||||
0.0f, //float Falloff; /* Falloff */
|
||||
1.0f / 4096.0f, //float Attenuation0; /* Constant attenuation */
|
||||
1.0f / 4096.0f, //float Attenuation1; /* Linear attenuation */
|
||||
1.0f / 4096.0f, //float Attenuation2; /* Quadratic attenuation */
|
||||
0.0f, //float Theta; /* Inner angle of spotlight cone */
|
||||
0.0f, //float Phi; /* Outer angle of spotlight cone */
|
||||
},
|
||||
{
|
||||
D3DLIGHT_POINT,// D3DLIGHTTYPE Type; /* Type of light source */
|
||||
{ 0.6f, 0.6f, 0.8f, 0.0f },// D3DCOLORVALUE Diffuse; /* Diffuse color of light */
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },// D3DCOLORVALUE Specular; /* Specular color of light */
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },// D3DCOLORVALUE Ambient; /* Ambient color of light */
|
||||
{ -16.0f, -32.0f, 64.0f },// D3DVECTOR Position; /* Position in world space */
|
||||
{ 0.0f, 0.0f, 0.0f },// D3DVECTOR Direction; /* Direction in world space */
|
||||
1024.0f, //float Range; /* Cutoff range */
|
||||
0.0f, //float Falloff; /* Falloff */
|
||||
1.0f / 4096.0f, //float Attenuation0; /* Constant attenuation */
|
||||
1.0f / 4096.0f, //float Attenuation1; /* Linear attenuation */
|
||||
1.0f / 4096.0f, //float Attenuation2; /* Quadratic attenuation */
|
||||
0.0f, //float Theta; /* Inner angle of spotlight cone */
|
||||
0.0f, //float Phi; /* Outer angle of spotlight cone */
|
||||
},
|
||||
|
||||
{
|
||||
D3DLIGHT_POINT,// D3DLIGHTTYPE Type; /* Type of light source */
|
||||
{ 141.0f / 255.0f, 122.0f / 255.0f, 57.0f / 255.0f, 0.0f },// D3DCOLORVALUE Diffuse; /* Diffuse color of light */
|
||||
{ 205.0f / 255.0f, 186.0f / 255.0f, 121.0f / 255.0f, 0.0f },// D3DCOLORVALUE Specular; /* Specular color of light */
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },// D3DCOLORVALUE Ambient; /* Ambient color of light */
|
||||
{ -48.0f, 64.0f, 48.0f },// D3DVECTOR Position; /* Position in world space */
|
||||
{ 0.0f, 0.0f, 0.0f },// D3DVECTOR Direction; /* Direction in world space */
|
||||
1024.0f, //float Range; /* Cutoff range */
|
||||
0.0f, //float Falloff; /* Falloff */
|
||||
1.0f / 4096.0f, //float Attenuation0; /* Constant attenuation */
|
||||
1.0f / 4096.0f, //float Attenuation1; /* Linear attenuation */
|
||||
1.0f / 4096.0f, //float Attenuation2; /* Quadratic attenuation */
|
||||
0.0f, //float Theta; /* Inner angle of spotlight cone */
|
||||
0.0f, //float Phi; /* Outer angle of spotlight cone */
|
||||
}
|
||||
};
|
||||
|
||||
D3DMATERIAL9 d3dMaterial=
|
||||
{
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },// D3DCOLORVALUE Diffuse; /* Diffuse color RGBA */
|
||||
{ 1.0f, 1.0f, 1.0f, 1.0f },// D3DCOLORVALUE Ambient; /* Ambient color RGB */
|
||||
{ 1.0f, 1.0f, 1.0f, 0.0f },// Specular; /* Specular 'shininess' */
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },// Emissive; /* Emissive color RGB */
|
||||
32.0f //float Power; /* Sharpness if specular highlight */
|
||||
};
|
||||
|
||||
struct STargetValue
|
||||
{
|
||||
float m_fValue;
|
||||
float m_fTarget;
|
||||
float m_fSpeed;
|
||||
float m_fAcceleration;
|
||||
float m_fFriction;
|
||||
|
||||
STargetValue
|
||||
( float fValue,
|
||||
float fTarget,
|
||||
float fSpeed,
|
||||
float fAcceleration,
|
||||
float fFriction )
|
||||
{
|
||||
m_fValue= fValue;
|
||||
m_fTarget= fTarget;
|
||||
m_fSpeed= fSpeed;
|
||||
m_fAcceleration= fAcceleration;
|
||||
m_fFriction= fFriction;
|
||||
}
|
||||
|
||||
void timeStep()
|
||||
{
|
||||
m_fValue+= m_fSpeed;
|
||||
float fDist= m_fTarget - m_fValue;
|
||||
m_fSpeed+= fDist * m_fAcceleration;
|
||||
m_fSpeed*= m_fFriction;
|
||||
}
|
||||
};
|
||||
|
||||
struct SCameraDescription
|
||||
{
|
||||
int m_iType;
|
||||
int m_iBaseBank;
|
||||
float m_fFov;
|
||||
|
||||
DWORD m_dwColor;
|
||||
float m_fFog;
|
||||
};
|
||||
|
||||
struct SObjectDescription
|
||||
{
|
||||
int m_iSizeX;
|
||||
int m_iSizeY;
|
||||
|
||||
int m_iBaseMeshType;
|
||||
int m_iBaseBank;
|
||||
|
||||
int m_iOffsetFunc;
|
||||
int m_iOffsetBank;
|
||||
|
||||
int m_iHeightFunc;
|
||||
int m_iHeightBank;
|
||||
|
||||
int m_iMixFunc;
|
||||
int m_iMixBank;
|
||||
|
||||
int m_iTransformFunc;
|
||||
int m_iTransformBank;
|
||||
|
||||
DWORD m_dwColor;
|
||||
};
|
||||
|
||||
struct SPortraitDescription
|
||||
{
|
||||
int m_iScale;
|
||||
|
||||
int m_iPosX;
|
||||
int m_iPosY;
|
||||
int m_iTextPosX;
|
||||
int m_iTextPosY;
|
||||
|
||||
int m_iTextureID;
|
||||
|
||||
char m_pcText[ 96 ];
|
||||
|
||||
int m_iTicks;
|
||||
};
|
||||
|
||||
enum ScriptCmd
|
||||
{
|
||||
QUIT,
|
||||
CSPEED,
|
||||
OSPEED,
|
||||
CTIME,
|
||||
OTIME,
|
||||
CAM,
|
||||
OBJ,
|
||||
TICK,
|
||||
};
|
||||
|
||||
#ifdef EXTRACODE
|
||||
float FloatParamBanks[ 4 * 512 ];
|
||||
SCameraDescription g_CameraData[ 64 ];
|
||||
SObjectDescription g_ObjectData[ 64 ];
|
||||
SPortraitDescription g_PortraitData[ 32 ];
|
||||
unsigned char g_Script[ 2048 ];
|
||||
float g_ScriptParamFloat[ 512 ];
|
||||
#else
|
||||
#include "globaldata.h"
|
||||
#include "scriptdata.h"
|
||||
#endif
|
||||
|
||||
float GetFloatParam( int iBank, int iIndex )
|
||||
{
|
||||
return FloatParamBanks[ 4 * iBank + iIndex ];
|
||||
}
|
||||
|
||||
#ifdef EXTRACODE
|
||||
void SetParamValue( int iBank, int iIndex, float fV )
|
||||
{
|
||||
FloatParamBanks[ 4 * iBank + iIndex ]= fV;
|
||||
}
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "StringHelper.h"
|
||||
#include "TextFileReader.h"
|
||||
|
||||
#include "ConfigFiles.h"
|
||||
|
||||
#endif
|
||||
|
||||
float signpow( float a, float b )
|
||||
{
|
||||
float fSign= ( a < 0.0f ? -1.0f : 1.0f );
|
||||
return fSign * (float)mypow( (float)fabs( (float)a ), b );
|
||||
|
||||
/*if( a < 0.0f )
|
||||
{
|
||||
return -(float)pow( -a, b );
|
||||
}
|
||||
else
|
||||
{
|
||||
return (float)pow( a, b );
|
||||
}*/
|
||||
}
|
||||
|
||||
void viewStraight()
|
||||
{
|
||||
D3DXMatrixLookAtLH( &matView,
|
||||
(D3DXVECTOR3*)&D3DXVECTOR3( 0.0f, 4.0f, 250.0f ),
|
||||
(D3DXVECTOR3*)&D3DXVECTOR3( 0.0f, 0.0f, -100.0f ),
|
||||
(D3DXVECTOR3*)&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
|
||||
g_d3d_device->SetTransform( D3DTS_VIEW, &matView );
|
||||
g_d3d_device->Clear( 0, NULL, D3DCLEAR_ZBUFFER ,0x000000ff, 1.0f, 0 );
|
||||
|
||||
}
|
||||
|
||||
#ifdef MUSICLOAD
|
||||
#include <stdio.h>
|
||||
unsigned char pLoadSong[ 65536 * 8 ];
|
||||
bool loadMusic()
|
||||
{
|
||||
OFSTRUCT File;
|
||||
HFILE file= OpenFile( "song.v2m",
|
||||
&File, //&fileInfo,
|
||||
OF_READ );
|
||||
HANDLE handle= (HANDLE)file;
|
||||
if( handle == NULL )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
DWORD dwRead;
|
||||
BOOL bRead= ReadFile( handle,
|
||||
pLoadSong,
|
||||
65536 * 8,
|
||||
&dwRead,
|
||||
NULL );
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "mesher.h"
|
||||
#include "camera.h"
|
||||
#include "picstuff.h"
|
||||
#include "bar16to9.h"
|
||||
|
||||
#include "textout.h"
|
||||
|
||||
void WinEntry(void)
|
||||
{
|
||||
#ifndef DISABLEAUTOSCREEN
|
||||
c_iScreenSizeX = GetSystemMetrics( SM_CXSCREEN );
|
||||
c_iScreenSizeY = GetSystemMetrics( SM_CYSCREEN );
|
||||
#endif
|
||||
/***********************************************************************************/
|
||||
char* pcCommand;
|
||||
pcCommand= GetCommandLine();
|
||||
{
|
||||
int i= 0;
|
||||
int iNumber= 0;
|
||||
int iBool= -1;
|
||||
{
|
||||
while( pcCommand[ i ] != 0 )
|
||||
{
|
||||
if( pcCommand[ i ] == '+' )
|
||||
{
|
||||
iBool= 1;
|
||||
iNumber= 0;
|
||||
}
|
||||
else if( pcCommand[ i ] == '-' )
|
||||
{
|
||||
iBool= 0;
|
||||
iNumber= 0;
|
||||
}
|
||||
else if( pcCommand[ i ] >= '0' && pcCommand[ i ] <= '9' )
|
||||
{
|
||||
iNumber= 10 * iNumber + pcCommand[ i ] - '0';
|
||||
}
|
||||
else if( pcCommand[ i ] == 'w' )
|
||||
{
|
||||
if( iBool != -1 )
|
||||
{
|
||||
bWindowed= iBool == 1;
|
||||
}
|
||||
iBool= -1;
|
||||
iNumber= 0;
|
||||
}
|
||||
else if( pcCommand[ i ] == 'l' )
|
||||
{
|
||||
if( iBool != -1 )
|
||||
{
|
||||
bLowDetail= iBool == 1;
|
||||
}
|
||||
iBool= -1;
|
||||
iNumber= 0;
|
||||
}
|
||||
else if( pcCommand[ i ] == 'x' )
|
||||
{
|
||||
if( iNumber > 0 )
|
||||
{
|
||||
c_iScreenSizeX= iNumber;
|
||||
}
|
||||
iNumber= 0;
|
||||
}
|
||||
else if( pcCommand[ i ] == 'y' )
|
||||
{
|
||||
if( iNumber > 0 )
|
||||
{
|
||||
c_iScreenSizeY= iNumber;
|
||||
}
|
||||
iNumber= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
iNumber= 0;
|
||||
iBool= -1;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/***********************************************************************************/
|
||||
|
||||
c_iRealScreenY= c_iScreenSizeX * 9 / 16;
|
||||
if( c_iRealScreenY > c_iScreenSizeY )
|
||||
{
|
||||
c_iRealScreenY= c_iScreenSizeY;
|
||||
}
|
||||
|
||||
HWND& hwnd= d3dpp.hDeviceWindow;
|
||||
hwnd = CreateWindow(
|
||||
"STATIC", /* Classname */
|
||||
WindowTitle, /* Title Text */
|
||||
WS_OVERLAPPEDWINDOW, /* default window */
|
||||
0, /* Windows decides the position */
|
||||
0, /* where the window ends up on the screen */
|
||||
c_iScreenSizeX, /* The programs width */
|
||||
c_iScreenSizeY, /* and height in pixels */
|
||||
NULL, /* The window is a child-window to desktop */
|
||||
NULL, /* No menu */
|
||||
0, //GetModuleHandle(NULL), /* Program Instance handler */
|
||||
NULL /* No Window Creation data */
|
||||
);
|
||||
|
||||
#ifndef _DEBUG
|
||||
ShowCursor(false);
|
||||
#endif
|
||||
|
||||
/***********************************************************************************/
|
||||
//D3D Creation
|
||||
g_D3D= Direct3DCreate9( D3D_SDK_VERSION );
|
||||
|
||||
|
||||
if( bWindowed )
|
||||
{
|
||||
ShowWindow (hwnd , SW_NORMAL );
|
||||
}
|
||||
d3dpp.Windowed = bWindowed;
|
||||
|
||||
d3dpp.BackBufferWidth= c_iScreenSizeX;
|
||||
d3dpp.BackBufferHeight= c_iScreenSizeY;
|
||||
|
||||
if( !bLowDetail )
|
||||
{
|
||||
if( g_d3d_device == NULL )
|
||||
{
|
||||
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
||||
}
|
||||
|
||||
if( g_d3d_device == NULL )
|
||||
{
|
||||
d3dpp.MultiSampleType= D3DMULTISAMPLE_8_SAMPLES;
|
||||
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
||||
}
|
||||
if( g_d3d_device == NULL )
|
||||
{
|
||||
d3dpp.MultiSampleType= D3DMULTISAMPLE_4_SAMPLES;
|
||||
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
||||
}
|
||||
if( g_d3d_device == NULL )
|
||||
{
|
||||
d3dpp.MultiSampleType= D3DMULTISAMPLE_2_SAMPLES;
|
||||
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( g_d3d_device == NULL )
|
||||
{
|
||||
d3dpp.MultiSampleType= D3DMULTISAMPLE_NONE;
|
||||
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
||||
}
|
||||
if( g_d3d_device == NULL )
|
||||
{
|
||||
d3dpp.MultiSampleType= D3DMULTISAMPLE_NONE;
|
||||
g_D3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_FPU_PRESERVE|D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&g_d3d_device);
|
||||
}
|
||||
|
||||
if( g_d3d_device == NULL )
|
||||
{
|
||||
MessageBox( NULL,
|
||||
"D3D not initialized!",
|
||||
"fatal Error",
|
||||
MB_OK );
|
||||
ExitProcess( -1 );
|
||||
}
|
||||
|
||||
|
||||
#ifdef EXTRACODE
|
||||
StartFileWatch();
|
||||
ReadDataFromDisc();
|
||||
#endif
|
||||
/***********************************************************************************/
|
||||
//Renderstates
|
||||
|
||||
g_d3d_device->SetMaterial( &d3dMaterial );
|
||||
|
||||
g_d3d_device->SetRenderState( D3DRS_SPECULARENABLE, TRUE );
|
||||
g_d3d_device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1 );
|
||||
g_d3d_device->SetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL );
|
||||
g_d3d_device->SetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1 );
|
||||
g_d3d_device->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );
|
||||
|
||||
//g_d3d_device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
||||
//g_d3d_device->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
|
||||
//g_d3d_device->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT );
|
||||
|
||||
/***********************************************************************************/
|
||||
//prep picture
|
||||
PrepareText();
|
||||
RenderLoading( 1 );
|
||||
CreatePictures();
|
||||
|
||||
/***********************************************************************************/
|
||||
// Sound
|
||||
// Sound
|
||||
#ifdef STARTMUSIC
|
||||
player.Init();
|
||||
# ifdef MUSICLOAD
|
||||
|
||||
if( loadMusic() )
|
||||
{
|
||||
player.Open(pLoadSong);
|
||||
}
|
||||
# else
|
||||
player.Open(pSong);
|
||||
# endif
|
||||
|
||||
dsInit(player.RenderProxy,&player,GetForegroundWindow());
|
||||
|
||||
#ifdef SCRIPTEDITOR
|
||||
player.Play( g_iSkipTicks * g_iTempo / 1411 );
|
||||
g_iSampleOffset= g_iSampleOffsetGeneral -
|
||||
g_iSkipTicks * g_iTempo / 32;
|
||||
#else
|
||||
player.Play();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/***********************************************************************************/
|
||||
//Mainloop
|
||||
|
||||
g_ScriptState.Prepare();
|
||||
|
||||
STargetValue tvBumping1( 1.0f, 1.0f, 0.0f, 0.05f, 0.85f );
|
||||
|
||||
do
|
||||
{
|
||||
#ifdef EXTRACODE
|
||||
if( CheckFileWatch() )
|
||||
{
|
||||
# ifndef STARTMUSIC
|
||||
g_dwTimeReplaceStart= timeGetTime();
|
||||
# else
|
||||
# ifdef SCRIPTEDITOR
|
||||
player.Play( g_iSkipTicks * g_iTempo / 1411 );
|
||||
g_iSampleOffset= player.GetPlayTick() +
|
||||
g_iSampleOffsetGeneral -
|
||||
g_iSkipTicks * g_iTempo / 32;
|
||||
# else
|
||||
player.Play();
|
||||
g_iSampleOffset= player.GetPlayTick() +
|
||||
g_iSampleOffsetGeneral;
|
||||
# endif
|
||||
# endif
|
||||
g_ScriptState.Prepare();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef STARTMUSIC
|
||||
g_dwSamplesPassed= (int)player.GetPlayTick() - g_iSampleOffset;
|
||||
#else
|
||||
g_dwSamplesPassed= (timeGetTime() - g_dwTimeReplaceStart ) * 441 / 10;
|
||||
#endif
|
||||
DWORD dwNewSamples= g_dwSamplesPassed - g_dwSamples;
|
||||
g_dwSamples= g_dwSamplesPassed;
|
||||
|
||||
/***********************************************************************************/
|
||||
//execute script
|
||||
int iCurTick= g_dwSamples * 32 / g_iTempo;
|
||||
while( iCurTick >= g_ScriptState.iTargetTick )
|
||||
{
|
||||
if( QUIT == g_Script[ g_ScriptState.iScriptPointer ] )
|
||||
{
|
||||
#ifdef DISABLEAUTOQUIT
|
||||
break;//g_ScriptParamFloat
|
||||
#else
|
||||
ExitProcess( 0 );
|
||||
#endif
|
||||
}
|
||||
ScriptCmd cmd= (ScriptCmd)g_Script[ g_ScriptState.iScriptPointer++ ];
|
||||
switch( cmd )
|
||||
{
|
||||
case CSPEED:
|
||||
g_ScriptState.m_fCamSpeed=
|
||||
g_ScriptParamFloat[ g_ScriptState.iScriptParam++ ];
|
||||
break;
|
||||
case OSPEED:
|
||||
g_ScriptState.m_fObjectSpeed=
|
||||
g_ScriptParamFloat[ g_ScriptState.iScriptParam++ ];
|
||||
break;
|
||||
case CTIME:
|
||||
g_ScriptState.m_fCamTime=
|
||||
g_ScriptParamFloat[ g_ScriptState.iScriptParam++ ];
|
||||
break;
|
||||
case OTIME:
|
||||
g_ScriptState.m_fObjectTime=
|
||||
g_ScriptParamFloat[ g_ScriptState.iScriptParam++ ];
|
||||
break;
|
||||
case CAM:
|
||||
g_ScriptState.m_iCam=
|
||||
g_Script[ g_ScriptState.iScriptPointer++ ];
|
||||
break;
|
||||
case OBJ:
|
||||
g_ScriptState.m_iObject=
|
||||
g_Script[ g_ScriptState.iScriptPointer++ ];
|
||||
g_ScriptState.m_iObjectCount=
|
||||
g_Script[ g_ScriptState.iScriptPointer++ ];
|
||||
break;
|
||||
case TICK:
|
||||
g_ScriptState.iTargetTick+=
|
||||
g_Script[ g_ScriptState.iScriptPointer++ ];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float fTimeStep= (float)dwNewSamples * 4.0f / (float)g_iTempo;
|
||||
g_ScriptState.m_fCamTime+= g_ScriptState.m_fCamSpeed * fTimeStep;
|
||||
g_ScriptState.m_fObjectTime+= g_ScriptState.m_fObjectSpeed * fTimeStep;
|
||||
|
||||
int iPortrait= g_ScriptState.m_iPorPointer;
|
||||
int iPorEnd= g_PortraitData[ iPortrait ].m_iTicks + g_ScriptState.m_iPorStartTick;
|
||||
if( iCurTick > iPorEnd && g_ScriptState.m_iPorPointer < 29 )
|
||||
{
|
||||
g_ScriptState.m_iPorStartTick+= g_PortraitData[ iPortrait ].m_iTicks;
|
||||
g_ScriptState.m_iPorPointer++;
|
||||
iPortrait++;
|
||||
}
|
||||
|
||||
#ifdef STARTMUSIC
|
||||
float fL, fR;
|
||||
player.GetChannelVU( 3, &fL, &fR );
|
||||
g_vuLightBeat.Set( g_dwSamples / 100 + 88, fL + fR );
|
||||
player.GetChannelVU( 2, &fL, &fR );
|
||||
g_vuOffBeat.Set( g_dwSamples / 100 + 88, fL + fR );
|
||||
#endif
|
||||
|
||||
float fRes= 1.0f - minimum( 1.0f,( g_vuLightBeat.Get( g_dwSamples / 100 ) ) * 0.475f );
|
||||
d3dMaterial.Power= 1.25f + mypow( fRes, 0.33f ) * 31.0f;
|
||||
g_d3d_device->SetMaterial( &d3dMaterial );
|
||||
|
||||
/***********************************************************************************/
|
||||
//begin paint loop
|
||||
g_d3d_device->BeginScene();
|
||||
|
||||
int iCamera= g_ScriptState.m_iCam;
|
||||
|
||||
#ifdef SINGLEEDITMODE
|
||||
iCamera= g_iCurrentCamera;
|
||||
#endif
|
||||
|
||||
D3DXMATRIX mat;
|
||||
|
||||
float zf= 400.0f;
|
||||
float zn= 0.125f;
|
||||
float xScale = g_CameraData[ iCamera ].m_fFov;
|
||||
float yScale= xScale / (float)c_iScreenSizeY * (float)c_iScreenSizeX;
|
||||
|
||||
mat._11= xScale; mat._12= 0; mat._13= 0; mat._14= 0;
|
||||
mat._21= 0; mat._22= yScale; mat._23= 0; mat._24= 0;
|
||||
mat._31= 0; mat._32= 0; mat._33= zf/(zf-zn); mat._34= 1;
|
||||
mat._41= 0; mat._42= 0; mat._43= -zn*zf/(zf-zn);mat._44= 0;
|
||||
|
||||
g_d3d_device->SetTransform( D3DTS_PROJECTION, &mat );
|
||||
|
||||
SetCamera( g_CameraData + iCamera, g_ScriptState.m_fCamTime );
|
||||
|
||||
g_d3d_device->Clear( 0, NULL, D3DCLEAR_TARGET| D3DCLEAR_ZBUFFER , g_CameraData[ iCamera ].m_dwColor, 1.0f, 0 );
|
||||
|
||||
g_d3d_device->SetRenderState(D3DRS_FOGCOLOR, g_CameraData[ iCamera ].m_dwColor );
|
||||
g_d3d_device->SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_EXP2);
|
||||
float fDensity= g_CameraData[ iCamera ].m_fFog;
|
||||
g_d3d_device->SetRenderState( D3DRS_FOGDENSITY, *(DWORD *)(&fDensity) );
|
||||
g_d3d_device->SetRenderState( D3DRS_FOGENABLE, TRUE );
|
||||
|
||||
int iCurObj= g_ScriptState.m_iObject;
|
||||
int iObjCount= g_ScriptState.m_iObjectCount;
|
||||
|
||||
#ifdef SINGLEEDITMODE
|
||||
iCurObj= g_iCurrentObject;
|
||||
iObjCount= g_iCurrentObjectCount;
|
||||
#endif
|
||||
while( iObjCount > 0 )
|
||||
{
|
||||
RenderMesh( g_ObjectData + iCurObj, g_ScriptState.m_fObjectTime );
|
||||
iCurObj++;
|
||||
iObjCount--;
|
||||
}
|
||||
|
||||
#ifndef SINGLEEDITMODE
|
||||
int iPercent= 46 + ( iCurTick / 4 ) * 2;
|
||||
if( iPercent < 100 )
|
||||
{
|
||||
RenderLoadingLine( iPercent );
|
||||
}
|
||||
#endif
|
||||
|
||||
# ifdef SINGLEEDITMODE
|
||||
iPortrait= g_iCurrentPortrait;
|
||||
# endif
|
||||
|
||||
if( g_PortraitData[ iPortrait ].m_iTextureID >= 0 )
|
||||
{
|
||||
const int iScrollTicks= 22050;
|
||||
int iTicksHere= g_dwSamples - g_ScriptState.m_iPorStartTick * g_iTempo / 32;
|
||||
int iTicksNext= iPorEnd * g_iTempo / 32 - g_dwSamples;
|
||||
|
||||
float fPosOffset= 0.0f;
|
||||
if( iTicksHere < iScrollTicks &&
|
||||
iPortrait > 0 &&
|
||||
g_PortraitData[ iPortrait ].m_iTextureID !=
|
||||
g_PortraitData[ iPortrait - 1 ].m_iTextureID )
|
||||
{
|
||||
fPosOffset= (float)( iScrollTicks - iTicksHere ) / (float)iScrollTicks;
|
||||
}
|
||||
else if( iTicksNext < iScrollTicks &&
|
||||
g_PortraitData[ iPortrait ].m_iTextureID !=
|
||||
g_PortraitData[ iPortrait + 1 ].m_iTextureID )
|
||||
{
|
||||
fPosOffset= (float)( iScrollTicks - iTicksNext ) / (float)iScrollTicks;
|
||||
}
|
||||
fPosOffset= fPosOffset * fPosOffset * 512.0f;
|
||||
if( g_PortraitData[ iPortrait ].m_iPosX < 0.0f )
|
||||
{
|
||||
fPosOffset= -fPosOffset;
|
||||
}
|
||||
|
||||
RenderPic(
|
||||
g_PortraitData[ iPortrait ].m_iTextureID,
|
||||
(float)g_PortraitData[ iPortrait ].m_iPosX + fPosOffset,
|
||||
(float)g_PortraitData[ iPortrait ].m_iPosY,
|
||||
(float)g_PortraitData[ iPortrait ].m_iScale );
|
||||
RenderText(
|
||||
g_PortraitData[ iPortrait ].m_pcText,
|
||||
iTicksHere * 8 / g_iTempo - 4,
|
||||
(float)g_PortraitData[ iPortrait ].m_iTextPosX,
|
||||
(float)g_PortraitData[ iPortrait ].m_iTextPosY );
|
||||
}
|
||||
//iWord++;
|
||||
RenderBars();
|
||||
g_d3d_device->EndScene();
|
||||
g_d3d_device->Present( NULL, NULL, NULL, NULL );
|
||||
/***********************************************************************************/
|
||||
#ifdef _DEBUG
|
||||
Sleep( 5 );
|
||||
#endif
|
||||
|
||||
/***********************************************************************************/
|
||||
} while ( !GetAsyncKeyState( VK_ESCAPE ) );
|
||||
|
||||
/***********************************************************************************/
|
||||
//Shutdown
|
||||
ExitProcess( 0 );
|
||||
}
|
||||
|
||||
#ifdef EXTRACODE
|
||||
|
||||
int WINAPI
|
||||
WinMain (HINSTANCE hInstance,
|
||||
HINSTANCE hPrevInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int iCmdShow)
|
||||
{
|
||||
WinEntry();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Declare Windows procedure */
|
||||
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
Reference in New Issue
Block a user