git-svn-id: http://svn.purei.org/purei/trunk@357 b36208d7-6611-0410-8bec-b1987f11c4a2

This commit is contained in:
jpd002 2008-08-07 18:25:13 +00:00
parent 4965042ad7
commit dd971b2500
15 changed files with 365 additions and 37 deletions

View File

@ -0,0 +1,19 @@
#include "AcceleratorTable.h"
using namespace Framework::Win32;
CAcceleratorTable::CAcceleratorTable(HACCEL accel) :
m_accel(accel)
{
}
CAcceleratorTable::~CAcceleratorTable()
{
DestroyAcceleratorTable(m_accel);
}
CAcceleratorTable::operator HACCEL()
{
return m_accel;
}

View File

@ -0,0 +1,23 @@
#ifndef _ACCELERATORTABLE_H_
#define _ACCELERATORTABLE_H_
#include "win32/Window.h"
namespace Framework
{
namespace Win32
{
class CAcceleratorTable
{
public:
CAcceleratorTable(HACCEL);
virtual ~CAcceleratorTable();
operator HACCEL();
private:
HACCEL m_accel;
};
}
}
#endif

View File

@ -0,0 +1,124 @@
#include "FileInformationWindow.h"
#include "win32/Rect.h"
#include "win32/Static.h"
#include "layout/LayoutEngine.h"
#include "string_cast.h"
#define CLSNAME _T("FileInformationWindow")
#define WNDSTYLE (WS_CAPTION | WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU)
#define WNDSTYLEEX (WS_EX_DLGMODALFRAME)
#define LABEL_COLUMN_WIDTH (50)
using namespace Framework;
using namespace std;
CFileInformationWindow::CFileInformationWindow(HWND parent, const CPsfBase::TagMap& tags) :
CModalWindow(parent),
m_tags(tags)
{
if(!DoesWindowClassExist(CLSNAME))
{
WNDCLASSEX w;
memset(&w, 0, sizeof(WNDCLASSEX));
w.cbSize = sizeof(WNDCLASSEX);
w.lpfnWndProc = CWindow::WndProc;
w.lpszClassName = CLSNAME;
w.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_BTNFACE);
w.hInstance = GetModuleHandle(NULL);
w.hCursor = LoadCursor(NULL, IDC_ARROW);
RegisterClassEx(&w);
}
Create(WNDSTYLEEX, CLSNAME, _T("File Information"), WNDSTYLE, Win32::CRect(0, 0, 400, 250), parent, NULL);
SetClassPtr();
m_title = new Win32::CEdit(m_hWnd, Win32::CRect(0, 0, 0, 0));
m_artist = new Win32::CEdit(m_hWnd, Win32::CRect(0, 0, 0, 0));
m_game = new Win32::CEdit(m_hWnd, Win32::CRect(0, 0, 0, 0));
m_year = new Win32::CEdit(m_hWnd, Win32::CRect(0, 0, 0, 0));
m_genre = new Win32::CEdit(m_hWnd, Win32::CRect(0, 0, 0, 0));
m_comment = new Win32::CEdit(m_hWnd, Win32::CRect(0, 0, 0, 0));
m_copyright = new Win32::CEdit(m_hWnd, Win32::CRect(0, 0, 0, 0));
m_psfBy = new Win32::CEdit(m_hWnd, Win32::CRect(0, 0, 0, 0));
m_layout =
VerticalLayoutContainer
(
HorizontalLayoutContainer
(
LayoutExpression(Win32::CLayoutWindow::CreateButtonBehavior(LABEL_COLUMN_WIDTH, 12, new Win32::CStatic(m_hWnd, _T("Title:")))) +
LayoutExpression(Win32::CLayoutWindow::CreateTextBoxBehavior(100, 20, m_title))
) +
HorizontalLayoutContainer
(
LayoutExpression(Win32::CLayoutWindow::CreateButtonBehavior(LABEL_COLUMN_WIDTH, 12, new Win32::CStatic(m_hWnd, _T("Artist:")))) +
LayoutExpression(Win32::CLayoutWindow::CreateTextBoxBehavior(100, 20, m_artist))
) +
HorizontalLayoutContainer
(
LayoutExpression(Win32::CLayoutWindow::CreateButtonBehavior(LABEL_COLUMN_WIDTH, 12, new Win32::CStatic(m_hWnd, _T("Game:")))) +
LayoutExpression(Win32::CLayoutWindow::CreateTextBoxBehavior(100, 20, m_game))
) +
HorizontalLayoutContainer
(
LayoutExpression(Win32::CLayoutWindow::CreateButtonBehavior(LABEL_COLUMN_WIDTH, 12, new Win32::CStatic(m_hWnd, _T("Year:")))) +
LayoutExpression(Win32::CLayoutWindow::CreateTextBoxBehavior(100, 20, m_year))
) +
HorizontalLayoutContainer
(
LayoutExpression(Win32::CLayoutWindow::CreateButtonBehavior(LABEL_COLUMN_WIDTH, 12, new Win32::CStatic(m_hWnd, _T("Genre:")))) +
LayoutExpression(Win32::CLayoutWindow::CreateTextBoxBehavior(100, 20, m_genre))
) +
HorizontalLayoutContainer
(
LayoutExpression(Win32::CLayoutWindow::CreateButtonBehavior(LABEL_COLUMN_WIDTH, 12, new Win32::CStatic(m_hWnd, _T("Comment:")))) +
LayoutExpression(Win32::CLayoutWindow::CreateTextBoxBehavior(100, 20, m_comment))
) +
HorizontalLayoutContainer
(
LayoutExpression(Win32::CLayoutWindow::CreateButtonBehavior(LABEL_COLUMN_WIDTH, 12, new Win32::CStatic(m_hWnd, _T("Copyright:")))) +
LayoutExpression(Win32::CLayoutWindow::CreateTextBoxBehavior(100, 20, m_copyright))
) +
HorizontalLayoutContainer
(
LayoutExpression(Win32::CLayoutWindow::CreateButtonBehavior(LABEL_COLUMN_WIDTH, 12, new Win32::CStatic(m_hWnd, _T("Psf by:")))) +
LayoutExpression(Win32::CLayoutWindow::CreateTextBoxBehavior(100, 20, m_psfBy))
) +
LayoutExpression(CLayoutStretch::Create())
);
RefreshLayout();
UpdateFields();
}
CFileInformationWindow::~CFileInformationWindow()
{
}
void CFileInformationWindow::RefreshLayout()
{
RECT rc = GetClientRect();
m_layout->SetRect(rc.left + 10, rc.top + 10, rc.right - 10, rc.bottom - 10);
m_layout->RefreshGeometry();
}
string CFileInformationWindow::GetTagValue(const char* tagName)
{
CPsfBase::TagMap::const_iterator tagIterator(m_tags.find(tagName));
if(tagIterator == m_tags.end()) return "";
return tagIterator->second;
}
void CFileInformationWindow::UpdateFields()
{
m_title->SetText(string_cast<tstring>(GetTagValue("title")).c_str());
m_artist->SetText(string_cast<tstring>(GetTagValue("artist")).c_str());
m_game->SetText(string_cast<tstring>(GetTagValue("game")).c_str());
m_year->SetText(string_cast<tstring>(GetTagValue("year")).c_str());
m_genre->SetText(string_cast<tstring>(GetTagValue("genre")).c_str());
m_comment->SetText(string_cast<tstring>(GetTagValue("comment")).c_str());
m_copyright->SetText(string_cast<tstring>(GetTagValue("copyright")).c_str());
m_psfBy->SetText(string_cast<tstring>(GetTagValue("psfby")).c_str());
}

View File

@ -0,0 +1,34 @@
#ifndef _FILEINFORMATIONWINDOW_H_
#define _FILEINFORMATIONWINDOW_H_
#include "win32/ModalWindow.h"
#include "win32/Edit.h"
#include "win32/Layouts.h"
#include "PsfBase.h"
class CFileInformationWindow : public Framework::Win32::CModalWindow
{
public:
CFileInformationWindow(HWND, const CPsfBase::TagMap&);
virtual ~CFileInformationWindow();
protected:
void RefreshLayout();
private:
std::string GetTagValue(const char*);
void UpdateFields();
CPsfBase::TagMap m_tags;
Framework::Win32::CEdit* m_title;
Framework::Win32::CEdit* m_artist;
Framework::Win32::CEdit* m_game;
Framework::Win32::CEdit* m_year;
Framework::Win32::CEdit* m_genre;
Framework::Win32::CEdit* m_comment;
Framework::Win32::CEdit* m_copyright;
Framework::Win32::CEdit* m_psfBy;
Framework::LayoutObjectPtr m_layout;
};
#endif

View File

@ -10,7 +10,7 @@ int main(int argc, char** argv)
{
CPsxVm virtualMachine;
#ifdef _DEBUG
#ifdef DEBUGGER_INCLUDED
{
virtualMachine.Reset();
CPsfLoader::LoadPsf(virtualMachine, "C:\\Media\\PSX\\FF7_psf\\FF7 408 Hurry Faster!.minipsf");
@ -27,7 +27,7 @@ int main(int argc, char** argv)
CPlayerWnd player(virtualMachine);
player.Center();
player.Show(SW_SHOW);
Win32::CWindow::StdMsgLoop(&player);
player.Run();
}
#endif

View File

@ -2,6 +2,8 @@
#include "PsfLoader.h"
#include "win32/Rect.h"
#include "win32/FileDialog.h"
#include "win32/AcceleratorTableGenerator.h"
#include "FileInformationWindow.h"
#include "string_cast.h"
#include "resource.h"
#include <afxres.h>
@ -19,7 +21,9 @@ using namespace std::tr1;
CPlayerWnd::CPlayerWnd(CPsxVm& virtualMachine) :
m_virtualMachine(virtualMachine),
m_frames(0),
m_regView(NULL)
m_regView(NULL),
m_ready(false),
m_accel(CreateAccelerators())
{
if(!DoesWindowClassExist(CLSNAME))
{
@ -36,6 +40,8 @@ m_regView(NULL)
m_regView = new CSpuRegView(m_hWnd, &GetClientRect(), m_virtualMachine.GetSpu());
m_regView->Show(SW_SHOW);
UpdateUi();
m_virtualMachine.OnNewFrame.connect(bind(&CPlayerWnd::OnNewFrame, this));
}
@ -45,6 +51,20 @@ CPlayerWnd::~CPlayerWnd()
delete m_regView;
}
void CPlayerWnd::Run()
{
while(IsWindow())
{
MSG msg;
GetMessage(&msg, 0, 0, 0);
if(!TranslateAccelerator(m_hWnd, m_accel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
long CPlayerWnd::OnSize(unsigned int, unsigned int, unsigned int)
{
if(m_regView != NULL)
@ -70,6 +90,12 @@ long CPlayerWnd::OnCommand(unsigned short id, unsigned short command, HWND hWndF
}
}
break;
case ID_FILE_PAUSE:
PauseResume();
break;
case ID_FILE_FILEINFORMATION:
ShowFileInformation();
break;
case ID_FILE_EXIT:
Destroy();
break;
@ -79,24 +105,70 @@ long CPlayerWnd::OnCommand(unsigned short id, unsigned short command, HWND hWndF
long CPlayerWnd::OnTimer()
{
TCHAR fps[32];
_stprintf(fps, _T("%i"), m_frames);
SetText(fps);
m_frames = 0;
// TCHAR fps[32];
// _stprintf(fps, _T("%i"), m_frames);
// SetText(fps);
// m_frames = 0;
return FALSE;
}
HACCEL CPlayerWnd::CreateAccelerators()
{
Win32::CAcceleratorTableGenerator tableGenerator;
tableGenerator.Insert(ID_FILE_PAUSE, VK_F5, FVIRTKEY);
return tableGenerator.Create();
}
void CPlayerWnd::PauseResume()
{
if(!m_ready) return;
if(m_virtualMachine.GetStatus() == CVirtualMachine::PAUSED)
{
m_virtualMachine.Resume();
}
else
{
m_virtualMachine.Pause();
}
}
void CPlayerWnd::ShowFileInformation()
{
if(!m_ready) return;
CFileInformationWindow fileInfo(m_hWnd, m_tags);
fileInfo.DoModal();
}
void CPlayerWnd::Load(const char* path)
{
m_virtualMachine.Pause();
m_virtualMachine.Reset();
CPsfLoader::LoadPsf(m_virtualMachine, path);
m_tags.clear();
CPsfLoader::LoadPsf(m_virtualMachine, path, &m_tags);
m_virtualMachine.Resume();
UpdateUi();
m_ready = true;
}
void CPlayerWnd::UpdateUi()
{
CPsfBase::ConstTagIterator titleTag = m_tags.find("title");
bool hasTitle = titleTag != m_tags.end();
tstring title = _T("PsfPlayer");
if(hasTitle)
{
title += _T(" - [ ");
title += string_cast<tstring>(titleTag->second);
title += _T(" ]");
}
SetText(title.c_str());
}
void CPlayerWnd::OnNewFrame()
{
m_regView->Render();
m_regView->Redraw();
m_frames++;
// m_frames++;
}

View File

@ -3,26 +3,39 @@
#include "PsxVm.h"
#include "win32/Window.h"
#include "AcceleratorTable.h"
#include "SpuRegView.h"
#include "PsfBase.h"
class CPlayerWnd : public Framework::Win32::CWindow
{
public:
CPlayerWnd(CPsxVm&);
virtual ~CPlayerWnd();
CPlayerWnd(CPsxVm&);
virtual ~CPlayerWnd();
void Run();
protected:
long OnSize(unsigned int, unsigned int, unsigned int);
long OnCommand(unsigned short, unsigned short, HWND);
long OnTimer();
long OnSize(unsigned int, unsigned int, unsigned int);
long OnCommand(unsigned short, unsigned short, HWND);
long OnTimer();
private:
void Load(const char*);
void OnNewFrame();
static HACCEL CreateAccelerators();
CPsxVm& m_virtualMachine;
CSpuRegView* m_regView;
unsigned int m_frames;
void Load(const char*);
void PauseResume();
void ShowFileInformation();
void OnNewFrame();
void UpdateUi();
CPsxVm& m_virtualMachine;
CSpuRegView* m_regView;
CPsfBase::TagMap m_tags;
unsigned int m_frames;
bool m_ready;
Framework::Win32::CAcceleratorTable m_accel;
};
#endif

View File

@ -56,6 +56,16 @@ const char* CPsfBase::GetTagValue(const char* name) const
return tagIterator->second.c_str();
}
CPsfBase::ConstTagIterator CPsfBase::GetTagsBegin() const
{
return m_tags.begin();
}
CPsfBase::ConstTagIterator CPsfBase::GetTagsEnd() const
{
return m_tags.end();
}
void CPsfBase::ReadProgram(CStream& stream)
{
assert(m_program == NULL);

View File

@ -9,6 +9,9 @@
class CPsfBase
{
public:
typedef std::map<std::string, std::string> TagMap;
typedef TagMap::const_iterator ConstTagIterator;
CPsfBase(Framework::CStream&);
virtual ~CPsfBase();
@ -25,24 +28,25 @@ public:
VERSION_CAPCOMQSOUND = 0x41
};
uint8* GetProgram() const;
const char* GetTagValue(const char*) const;
uint8* GetProgram() const;
const char* GetTagValue(const char*) const;
ConstTagIterator GetTagsBegin() const;
ConstTagIterator GetTagsEnd() const;
private:
typedef std::map<std::string, std::string> TagMap;
void ReadProgram(Framework::CStream&);
void ReadTags(Framework::CStream&);
void ReadProgram(Framework::CStream&);
void ReadTags(Framework::CStream&);
uint8 m_version;
uint32 m_reservedSize;
uint32 m_programSize;
uint32 m_programCrc;
uint8 m_version;
uint32 m_reservedSize;
uint32 m_programSize;
uint32 m_programCrc;
uint8* m_reserved;
uint8* m_program;
uint8* m_reserved;
uint8* m_program;
TagMap m_tags;
TagMap m_tags;
};
#endif

View File

@ -1,17 +1,20 @@
#include "PsfLoader.h"
#include "StdStream.h"
#include "PsfBase.h"
#include <boost/filesystem.hpp>
using namespace Framework;
using namespace Psx;
using namespace boost;
void CPsfLoader::LoadPsf(CPsxVm& virtualMachine, const char* pathString)
void CPsfLoader::LoadPsf(CPsxVm& virtualMachine, const char* pathString, CPsfBase::TagMap* tags)
{
CStdStream input(pathString, "rb");
CPsfBase psfFile(input);
const char* libPath = psfFile.GetTagValue("_lib");
if(tags)
{
tags->insert(psfFile.GetTagsBegin(), psfFile.GetTagsEnd());
}
uint32 sp = 0, pc = 0;
if(libPath != NULL)
{

View File

@ -2,13 +2,14 @@
#define _PSFLOADER_H_
#include "PsxVm.h"
#include "PsfBase.h"
namespace Psx
{
class CPsfLoader
{
public:
static void LoadPsf(CPsxVm&, const char*);
static void LoadPsf(CPsxVm&, const char*, CPsfBase::TagMap* = NULL);
};
}

View File

@ -240,7 +240,7 @@ void CPsxVm::ThreadProc()
}
else
{
#ifdef _DEBUG
#ifdef DEBUGGER_INCLUDED
int ticks = ExecuteCpu(m_singleStep);
static int frameCounter = frameTicks;

View File

@ -65,6 +65,8 @@ BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Open...", ID_FILE_OPEN
MENUITEM "&File Information...", ID_FILE_FILEINFORMATION
MENUITEM "Pause/Resume", ID_FILE_PAUSE
MENUITEM "Exit\tAlt+F4", ID_FILE_EXIT
END
END

View File

@ -8,13 +8,16 @@
#define IDR_MENU1 104
#define IDR_MAINMENU 104
#define ID_FILE_EXIT 40002
#define ID_FILE_FILEINFORMATION 40003
#define ID_VIRTUALMACHINE_PAUSE 40004
#define ID_FILE_PAUSE 40005
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_COMMAND_VALUE 40006
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif

View File

@ -41,7 +41,7 @@
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;C:\Program Files\OpenAL 1.1 SDK\include&quot;;C:\Projects\Rawr\Source;C:\Projects\zlib;C:\Components\boost_1_35_0\boost\tr1\tr1;C:\Components\boost_1_35_0;C:\Projects\Framework\include;C:\Projects\Rawr\tools\PsfPlayer\Source"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_MSVC;DEBUGGER_INCLUDED"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_MSVC"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@ -180,6 +180,14 @@
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\Source\AcceleratorTable.cpp"
>
</File>
<File
RelativePath=".\Source\AcceleratorTable.h"
>
</File>
<File
RelativePath=".\Source\CounterRegView.cpp"
>
@ -204,6 +212,14 @@
RelativePath=".\Source\DmaChannel.h"
>
</File>
<File
RelativePath=".\Source\FileInformationWindow.cpp"
>
</File>
<File
RelativePath=".\Source\FileInformationWindow.h"
>
</File>
<File
RelativePath=".\Source\FunctionsView.cpp"
>
@ -684,6 +700,10 @@
<Filter
Name="Framework"
>
<File
RelativePath="..\..\..\Framework\src\win32\AcceleratorTableGenerator.cpp"
>
</File>
<File
RelativePath="..\..\..\Framework\src\openal\Buffer.cpp"
>