forked from 0ad/0ad
Initial parts of Atlas integration
This was SVN commit r2435.
This commit is contained in:
parent
470681a287
commit
5c4d41fd0f
@ -51,8 +51,8 @@ static BOOL CALLBACK is_this_our_window(HWND hWnd, LPARAM lParam)
|
||||
DWORD tid = GetWindowThreadProcessId(hWnd, &pid);
|
||||
UNUSED(tid); // the function can't fail
|
||||
|
||||
DWORD our_pid = GetProcessId(GetCurrentProcess());
|
||||
if(pid == GetProcessId(GetCurrentProcess()))
|
||||
DWORD our_pid = GetCurrentProcessId();
|
||||
if(pid == GetCurrentProcessId())
|
||||
{
|
||||
*(HWND*)lParam = hWnd;
|
||||
return FALSE; // done
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
//#define ATLAS
|
||||
|
||||
#ifdef SCED
|
||||
# include "ui/StdAfx.h"
|
||||
# undef ERROR
|
||||
@ -129,7 +131,9 @@ CStr g_ActiveProfile = "default";
|
||||
extern size_t frameCount;
|
||||
static bool quit = false; // break out of main loop
|
||||
|
||||
|
||||
#ifdef ATLAS
|
||||
static bool g_Atlas = true; // allows startup in Atlas vs non-Atlas (game) modes
|
||||
#endif
|
||||
|
||||
|
||||
const wchar_t* HardcodedErrorString(int err)
|
||||
@ -1356,7 +1360,7 @@ static void Frame()
|
||||
{
|
||||
MICROLOG(L"In frame");
|
||||
|
||||
|
||||
|
||||
PROFILE_START( "update music" );
|
||||
MusicPlayer.update();
|
||||
PROFILE_END( "update music" );
|
||||
@ -1479,31 +1483,59 @@ static void Frame()
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
debug_printf("MAIN &argc=%p &argv=%p\n", &argc, &argv);
|
||||
debug_printf("MAIN &argc=%p &argv=%p\n", &argc, &argv);
|
||||
|
||||
// MICROLOG(L"In main");
|
||||
|
||||
// MICROLOG(L"Init");
|
||||
Init(argc, argv, true);
|
||||
|
||||
// Optionally, do some simple tests to ensure things aren't broken
|
||||
// extern void PerformTests();
|
||||
// PerformTests();
|
||||
|
||||
while(!quit)
|
||||
#ifdef ATLAS
|
||||
if (g_Atlas)
|
||||
{
|
||||
MICROLOG(L"(Simulation) Frame");
|
||||
Frame();
|
||||
extern void BeginAtlas(int, char**);
|
||||
BeginAtlas(argc, argv);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// MICROLOG(L"In main");
|
||||
|
||||
MICROLOG(L"Shutdown");
|
||||
Shutdown();
|
||||
|
||||
// MICROLOG(L"Init");
|
||||
Init(argc, argv, true);
|
||||
|
||||
// Optionally, do some simple tests to ensure things aren't broken
|
||||
// extern void PerformTests();
|
||||
// PerformTests();
|
||||
|
||||
while(!quit)
|
||||
{
|
||||
MICROLOG(L"(Simulation) Frame");
|
||||
Frame();
|
||||
}
|
||||
|
||||
MICROLOG(L"Shutdown");
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
delete &g_Profiler;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Public functions for Atlas to use:
|
||||
// TODO: Make this far less hacky
|
||||
void Init_(int argc, char** argv, bool setup_gfx)
|
||||
{
|
||||
g_Quickstart = true;
|
||||
Init(argc, argv, setup_gfx);
|
||||
}
|
||||
void Shutdown_()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
void Render_()
|
||||
{
|
||||
Render();
|
||||
}
|
||||
|
||||
|
||||
#else // SCED:
|
||||
|
||||
void ScEd_Init()
|
||||
|
@ -6,6 +6,6 @@
|
||||
#include "AtlasUI/Misc/DLLInterface.h"
|
||||
|
||||
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int) {
|
||||
StartWindow(L"ActorEditor");
|
||||
Atlas_StartWindow(L"ActorEditor");
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,6 +6,6 @@
|
||||
#include "AtlasUI/Misc/DLLInterface.h"
|
||||
|
||||
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int) {
|
||||
StartWindow(L"ColourTester");
|
||||
Atlas_StartWindow(L"ColourTester");
|
||||
return 0;
|
||||
}
|
||||
|
@ -6,6 +6,6 @@
|
||||
#include "AtlasUI/Misc/DLLInterface.h"
|
||||
|
||||
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int) {
|
||||
StartWindow(L"$$WINDOW_NAME$$");
|
||||
Atlas_StartWindow(L"$$WINDOW_NAME$$");
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="comctl32.lib rpcrt4.lib"
|
||||
AdditionalDependencies="comctl32.lib rpcrt4.lib wxmsw25ud_gl.lib"
|
||||
OutputFile="$(OutDir)/AtlasUI_d.dll"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="E:\wx\wxWidgets\lib\vc_lib;..\..\..\..\libraries\xerces\lib;..\..\..\..\libraries\devil\src\lib"
|
||||
@ -333,6 +333,16 @@
|
||||
RelativePath=".\ColourTester\ColourTesterImageCtrl.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="ScenarioEditor"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\ScenarioEditor\ScenarioEditor.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\ScenarioEditor\ScenarioEditor.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\TODO.txt">
|
||||
|
@ -1,6 +1,6 @@
|
||||
class ColourTesterImageCtrl;
|
||||
|
||||
DECLARE_EVENT_TYPE(wxEVT_MY_IMAGE_CHANGED, -1)
|
||||
DECLARE_EVENT_TYPE(wxEVT_MY_IMAGE_CHANGED, -1);
|
||||
|
||||
class ColourTester : public wxFrame
|
||||
{
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include "Datafile.h"
|
||||
#include "ActorEditor/ActorEditor.h"
|
||||
#include "ColourTester/ColourTester.h"
|
||||
#include "ScenarioEditor/ScenarioEditor.h"
|
||||
|
||||
#include "GameInterface/MessageHandler.h"
|
||||
|
||||
#include "wx/config.h"
|
||||
|
||||
@ -34,8 +37,14 @@ BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID WXUNUSED(lpRese
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
AtlasMessage::MessageHandler* AtlasMessage::g_MessageHandler = NULL;
|
||||
|
||||
ATLASDLLIMPEXP void StartWindow(wchar_t* type)
|
||||
ATLASDLLIMPEXP void Atlas_SetMessageHandler(AtlasMessage::MessageHandler* handler)
|
||||
{
|
||||
AtlasMessage::g_MessageHandler = handler;
|
||||
}
|
||||
|
||||
ATLASDLLIMPEXP void Atlas_StartWindow(wchar_t* type)
|
||||
{
|
||||
g_InitialWindowType = type;
|
||||
wxEntry(g_Module);
|
||||
@ -61,6 +70,8 @@ public:
|
||||
frame = new ActorEditor(NULL);
|
||||
else if (g_InitialWindowType == _T("ColourTester"))
|
||||
frame = new ColourTester(NULL);
|
||||
else if (g_InitialWindowType == _T("ScenarioEditor"))
|
||||
frame = new ScenarioEditor();
|
||||
else
|
||||
{
|
||||
wxFAIL_MSG(_("Internal error: invalid window type"));
|
||||
@ -70,18 +81,22 @@ public:
|
||||
frame->Show();
|
||||
SetTopWindow(frame);
|
||||
|
||||
// One argument => argv[1] is a filename to open
|
||||
// One argument => argv[1] is probably a filename to open
|
||||
if (argc > 1)
|
||||
{
|
||||
wxChar* filename = argv[1];
|
||||
if (wxFile::Exists(filename))
|
||||
|
||||
if (filename[0] != _T('-')) // ignore -options
|
||||
{
|
||||
AtlasWindow* win = wxDynamicCast(frame, AtlasWindow);
|
||||
if (win)
|
||||
win->OpenFile(filename);
|
||||
if (wxFile::Exists(filename))
|
||||
{
|
||||
AtlasWindow* win = wxDynamicCast(frame, AtlasWindow);
|
||||
if (win)
|
||||
win->OpenFile(filename);
|
||||
}
|
||||
else
|
||||
wxLogError(_("Cannot find file '%s'"), filename);
|
||||
}
|
||||
else
|
||||
wxLogError(_("Cannot find file '%s'"), filename);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1,3 +1,6 @@
|
||||
#include <wchar.h>
|
||||
|
||||
ATLASDLLIMPEXP void StartWindow(wchar_t* type);
|
||||
namespace AtlasMessage { class MessageHandler; }
|
||||
|
||||
ATLASDLLIMPEXP void Atlas_SetMessageHandler(AtlasMessage::MessageHandler*);
|
||||
ATLASDLLIMPEXP void Atlas_StartWindow(wchar_t* type);
|
||||
|
85
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp
Normal file
85
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "ScenarioEditor.h"
|
||||
|
||||
#include "wx/glcanvas.h"
|
||||
|
||||
#include "GameInterface/MessageHandler.h"
|
||||
#include "GameInterface/Messages.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Canvas : public wxGLCanvas
|
||||
{
|
||||
public:
|
||||
Canvas(wxWindow* parent, int* attribList)
|
||||
: wxGLCanvas(parent, -1, wxDefaultPosition, wxDefaultSize, 0, _T("GLCanvas"), attribList),
|
||||
m_SuppressResize(true)
|
||||
{
|
||||
}
|
||||
|
||||
void OnResize(wxSizeEvent&)
|
||||
{
|
||||
if (! m_SuppressResize)
|
||||
AtlasMessage::g_MessageHandler->Add(new AtlasMessage::mResizeScreen(GetSize().GetWidth(), GetSize().GetHeight()));
|
||||
}
|
||||
|
||||
void InitSize()
|
||||
{
|
||||
m_SuppressResize = false;
|
||||
SetSize(320, 240);
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_SuppressResize;
|
||||
DECLARE_EVENT_TABLE();
|
||||
};
|
||||
BEGIN_EVENT_TABLE(Canvas, wxGLCanvas)
|
||||
EVT_SIZE(Canvas::OnResize)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BEGIN_EVENT_TABLE(ScenarioEditor, wxFrame)
|
||||
EVT_CLOSE(ScenarioEditor::OnClose)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
ScenarioEditor::ScenarioEditor()
|
||||
: wxFrame(NULL, wxID_ANY, _("Atlas - Scenario Editor"))
|
||||
{
|
||||
wxPanel* panel = new wxPanel(this);
|
||||
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
|
||||
panel->SetSizer(sizer);
|
||||
|
||||
int glAttribList[] = {
|
||||
WX_GL_RGBA,
|
||||
WX_GL_DOUBLEBUFFER,
|
||||
WX_GL_DEPTH_SIZE, 24,
|
||||
0
|
||||
};
|
||||
Canvas* canvas = new Canvas(panel, glAttribList);
|
||||
// The canvas' context gets made current on creation; but it can only be
|
||||
// current for one thread at a time, and it needs to be current for the
|
||||
// thread that is doing the draw calls, so disable it for this one.
|
||||
wglMakeCurrent(NULL, NULL);
|
||||
|
||||
sizer->Add(canvas, wxSizerFlags().Proportion(1).Expand());
|
||||
|
||||
AtlasMessage::g_MessageHandler->Add(new AtlasMessage::mSetContext(canvas->GetHDC(), canvas->GetContext()->GetGLRC()));
|
||||
|
||||
AtlasMessage::g_MessageHandler->Add(new AtlasMessage::mCommandString("init"));
|
||||
|
||||
canvas->InitSize();
|
||||
|
||||
AtlasMessage::g_MessageHandler->Add(new AtlasMessage::mCommandString("render_enable"));
|
||||
}
|
||||
|
||||
void ScenarioEditor::OnClose(wxCloseEvent&)
|
||||
{
|
||||
AtlasMessage::g_MessageHandler->Add(new AtlasMessage::mCommandString("shutdown"));
|
||||
AtlasMessage::g_MessageHandler->Add(new AtlasMessage::mCommandString("exit"));
|
||||
|
||||
// TODO: What if it's still rendering while we're destroying the canvas?
|
||||
Destroy();
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
class ScenarioEditor : public wxFrame
|
||||
{
|
||||
public:
|
||||
ScenarioEditor();
|
||||
void OnClose(wxCloseEvent& evt);
|
||||
|
||||
DECLARE_EVENT_TABLE();
|
||||
};
|
133
source/tools/atlas/GameInterface/GameLoop.cpp
Normal file
133
source/tools/atlas/GameInterface/GameLoop.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "MessageHandlerImpl.h"
|
||||
#include "Messages.h"
|
||||
|
||||
#include "lib/sdl.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "renderer/Renderer.h"
|
||||
|
||||
using namespace AtlasMessage;
|
||||
|
||||
extern __declspec(dllimport) void Atlas_StartWindow(wchar_t* type);
|
||||
extern __declspec(dllimport) void Atlas_SetMessageHandler(MessageHandler*);
|
||||
|
||||
static MessageHandlerImpl msgHandler;
|
||||
|
||||
static void* LaunchWindow(void*)
|
||||
{
|
||||
Atlas_StartWindow(L"ScenarioEditor");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern void Init_(int argc, char** argv, bool setup_gfx);
|
||||
extern void Shutdown_();
|
||||
extern void Render_();
|
||||
|
||||
extern int g_xres, g_yres;
|
||||
|
||||
extern "C" { __declspec(dllimport) int __stdcall SwapBuffers(void*); }
|
||||
// HACK (and not exactly portable)
|
||||
//
|
||||
// (Er, actually that's what most of this file is. Oh well.)
|
||||
|
||||
|
||||
void BeginAtlas(int argc, char** argv)
|
||||
{
|
||||
Atlas_SetMessageHandler(&msgHandler);
|
||||
|
||||
pthread_t gameThread;
|
||||
pthread_create(&gameThread, NULL, LaunchWindow, NULL);
|
||||
|
||||
bool running = true;
|
||||
bool rendering = false;
|
||||
HDC currentDC = NULL;
|
||||
|
||||
while (running)
|
||||
{
|
||||
IMessage* msg;
|
||||
while (msg = msgHandler.Retrieve())
|
||||
{
|
||||
switch (msg->GetType())
|
||||
{
|
||||
case CommandString:
|
||||
{
|
||||
mCommandString* cmd = static_cast<mCommandString*>(msg);
|
||||
|
||||
if (cmd->name == "init")
|
||||
{
|
||||
oglInit();
|
||||
Init_(argc, argv, false);
|
||||
}
|
||||
else if (cmd->name == "render_enable")
|
||||
{
|
||||
rendering = true;
|
||||
}
|
||||
else if (cmd->name == "render_disable")
|
||||
{
|
||||
rendering = false;
|
||||
}
|
||||
else if (cmd->name == "shutdown")
|
||||
{
|
||||
Shutdown_();
|
||||
}
|
||||
else if (cmd->name == "exit")
|
||||
{
|
||||
running = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(ERROR, "atlas", "Unrecognised command string (%s)", cmd->name.c_str());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SetContext:
|
||||
{
|
||||
mSetContext* cmd = static_cast<mSetContext*>(msg);
|
||||
// TODO: portability
|
||||
wglMakeCurrent(cmd->hdc, cmd->hglrc);
|
||||
currentDC = cmd->hdc;
|
||||
}
|
||||
break;
|
||||
|
||||
case ResizeScreen:
|
||||
{
|
||||
mResizeScreen* cmd = static_cast<mResizeScreen*>(msg);
|
||||
g_xres = cmd->width;
|
||||
g_yres = cmd->height;
|
||||
if (g_xres == 0) g_xres = 160;
|
||||
if (g_yres == 0) g_yres = 120;
|
||||
SViewPort vp;
|
||||
vp.m_X = vp.m_Y = 0;
|
||||
vp.m_Width = g_xres;
|
||||
vp.m_Height = g_yres;
|
||||
g_Renderer.SetViewport(vp);
|
||||
g_GUI.UpdateResolution();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG(ERROR, "atlas", "Unrecognised message (%d)", msg->GetType());
|
||||
break;
|
||||
}
|
||||
|
||||
delete msg;
|
||||
}
|
||||
|
||||
if (! running)
|
||||
break;
|
||||
|
||||
if (rendering)
|
||||
{
|
||||
Render_();
|
||||
SwapBuffers(currentDC);
|
||||
}
|
||||
|
||||
SDL_Delay(100);
|
||||
}
|
||||
|
||||
pthread_join(gameThread, NULL);
|
||||
}
|
1
source/tools/atlas/GameInterface/GameLoop.h
Normal file
1
source/tools/atlas/GameInterface/GameLoop.h
Normal file
@ -0,0 +1 @@
|
||||
|
26
source/tools/atlas/GameInterface/MessageHandler.h
Normal file
26
source/tools/atlas/GameInterface/MessageHandler.h
Normal file
@ -0,0 +1,26 @@
|
||||
namespace AtlasMessage
|
||||
{
|
||||
struct IMessage;
|
||||
|
||||
class MessageHandler
|
||||
{
|
||||
public:
|
||||
virtual void Add(IMessage*)=0;
|
||||
virtual IMessage* Retrieve()=0;
|
||||
|
||||
virtual void Query(IMessage&)=0;
|
||||
virtual void QueryDone()=0;
|
||||
};
|
||||
|
||||
extern MessageHandler* g_MessageHandler;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
atlas->game command ("initialise now", "render now")
|
||||
atlas->game->atlas query ("what is at position (x,y)?")
|
||||
game->atlas notification ("game ended") ??
|
||||
|
||||
*/
|
40
source/tools/atlas/GameInterface/MessageHandlerImpl.cpp
Normal file
40
source/tools/atlas/GameInterface/MessageHandlerImpl.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "MessageHandlerImpl.h"
|
||||
|
||||
using namespace AtlasMessage;
|
||||
|
||||
void MessageHandlerImpl::Add(IMessage* msg)
|
||||
{
|
||||
m_Mutex.Lock();
|
||||
|
||||
m_Queue.push(msg);
|
||||
|
||||
m_Mutex.Unlock();
|
||||
}
|
||||
|
||||
IMessage* MessageHandlerImpl::Retrieve()
|
||||
{
|
||||
m_Mutex.Lock();
|
||||
|
||||
IMessage* msg = NULL;
|
||||
if (! m_Queue.empty())
|
||||
{
|
||||
msg = m_Queue.front();
|
||||
m_Queue.pop();
|
||||
}
|
||||
|
||||
m_Mutex.Unlock();
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
void MessageHandlerImpl::Query(IMessage&)
|
||||
{
|
||||
}
|
||||
|
||||
void MessageHandlerImpl::QueryDone()
|
||||
{
|
||||
}
|
||||
|
||||
MessageHandler* g_MessageHandler = NULL;
|
19
source/tools/atlas/GameInterface/MessageHandlerImpl.h
Normal file
19
source/tools/atlas/GameInterface/MessageHandlerImpl.h
Normal file
@ -0,0 +1,19 @@
|
||||
#include "MessageHandler.h"
|
||||
|
||||
#include "ps/ThreadUtil.h"
|
||||
#include <queue>
|
||||
|
||||
class MessageHandlerImpl : public AtlasMessage::MessageHandler
|
||||
{
|
||||
public:
|
||||
virtual void Add(AtlasMessage::IMessage* msg);
|
||||
virtual AtlasMessage::IMessage* Retrieve();
|
||||
|
||||
virtual void Query(AtlasMessage::IMessage&);
|
||||
virtual void QueryDone();
|
||||
|
||||
private:
|
||||
CMutex m_Mutex;
|
||||
std::queue<AtlasMessage::IMessage*> m_Queue;
|
||||
};
|
||||
|
38
source/tools/atlas/GameInterface/Messages.h
Normal file
38
source/tools/atlas/GameInterface/Messages.h
Normal file
@ -0,0 +1,38 @@
|
||||
namespace AtlasMessage
|
||||
{
|
||||
|
||||
struct IMessage
|
||||
{
|
||||
virtual int GetType() = 0;
|
||||
virtual ~IMessage() {}
|
||||
};
|
||||
|
||||
enum {
|
||||
CommandString,
|
||||
SetContext,
|
||||
ResizeScreen,
|
||||
};
|
||||
|
||||
struct mCommandString : public IMessage
|
||||
{
|
||||
mCommandString(const std::string& n) : name(n) {};
|
||||
const std::string name;
|
||||
virtual int GetType() { return CommandString; }
|
||||
};
|
||||
|
||||
struct mSetContext : public IMessage
|
||||
{
|
||||
mSetContext(void* /* HDC */ dc, void* /* HGLRC */ cx) : hdc(dc), hglrc(cx) {};
|
||||
void* hdc;
|
||||
void* hglrc;
|
||||
virtual int GetType() { return SetContext; }
|
||||
};
|
||||
|
||||
struct mResizeScreen : public IMessage
|
||||
{
|
||||
mResizeScreen(int w, int h) : width(w), height(h) {}
|
||||
int width, height;
|
||||
virtual int GetType() { return ResizeScreen; }
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user