Changeset View
Standalone View
source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* wxWidgets only registers the double click on mousedown. | * wxWidgets only registers the double click on mousedown. | ||||
*/ | */ | ||||
static int g_Clicks = 1; | static int g_Clicks = 1; | ||||
using namespace AtlasMessage; | using namespace AtlasMessage; | ||||
enum TIMER_TYPE | |||||
Stan: Maybe you could use enum class. | |||||
{ | |||||
TIMER_TOOL, | |||||
TIMER_RENDER | |||||
}; | |||||
// This records the last activity on the WX side. | |||||
double last_wx_user_activity = 0.0; | |||||
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// | ||||
// GL functions exported from DLL, and called by game (in a separate | // GL functions exported from DLL, and called by game (in a separate | ||||
// thread to the standard wx one) | // thread to the standard wx one) | ||||
ATLASDLLIMPEXP void Atlas_GLSetCurrent(void* canvas) | ATLASDLLIMPEXP void Atlas_GLSetCurrent(void* canvas) | ||||
{ | { | ||||
static_cast<Canvas*>(canvas)->SetCurrent(); | static_cast<Canvas*>(canvas)->SetCurrent(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | private: | ||||
} | } | ||||
void OnKeyDown(wxKeyEvent& evt) | void OnKeyDown(wxKeyEvent& evt) | ||||
{ | { | ||||
if (m_ScenarioEditor.GetToolManager().GetCurrentTool()->OnKey(evt, ITool::KEY_DOWN)) | if (m_ScenarioEditor.GetToolManager().GetCurrentTool()->OnKey(evt, ITool::KEY_DOWN)) | ||||
{ | { | ||||
// Key event has been handled by the tool, so don't try | // Key event has been handled by the tool, so don't try | ||||
// to use it for camera motion too | // to use it for camera motion too | ||||
last_wx_user_activity = g_Timer.GetTime(); | |||||
return; | return; | ||||
} | } | ||||
if (KeyScroll(evt, true)) | if (KeyScroll(evt, true)) | ||||
return; | return; | ||||
POST_MESSAGE(GuiKeyEvent, (GetSDLKeyFromWxKeyCode(evt.GetKeyCode()), evt.GetUnicodeKey(), true)); | POST_MESSAGE(GuiKeyEvent, (GetSDLKeyFromWxKeyCode(evt.GetKeyCode()), evt.GetUnicodeKey(), true)); | ||||
evt.Skip(); | evt.Skip(); | ||||
} | } | ||||
void OnKeyUp(wxKeyEvent& evt) | void OnKeyUp(wxKeyEvent& evt) | ||||
{ | { | ||||
if (m_ScenarioEditor.GetToolManager().GetCurrentTool()->OnKey(evt, ITool::KEY_UP)) | if (m_ScenarioEditor.GetToolManager().GetCurrentTool()->OnKey(evt, ITool::KEY_UP)) | ||||
{ | |||||
last_wx_user_activity = g_Timer.GetTime(); | |||||
return; | return; | ||||
} | |||||
if (KeyScroll(evt, false)) | if (KeyScroll(evt, false)) | ||||
return; | return; | ||||
POST_MESSAGE(GuiKeyEvent, (GetSDLKeyFromWxKeyCode(evt.GetKeyCode()), evt.GetUnicodeKey(), false)); | POST_MESSAGE(GuiKeyEvent, (GetSDLKeyFromWxKeyCode(evt.GetKeyCode()), evt.GetUnicodeKey(), false)); | ||||
evt.Skip(); | evt.Skip(); | ||||
} | } | ||||
void OnChar(wxKeyEvent& evt) | void OnChar(wxKeyEvent& evt) | ||||
{ | { | ||||
if (m_ScenarioEditor.GetToolManager().GetCurrentTool()->OnKey(evt, ITool::KEY_CHAR)) | if (m_ScenarioEditor.GetToolManager().GetCurrentTool()->OnKey(evt, ITool::KEY_CHAR)) | ||||
{ | |||||
last_wx_user_activity = g_Timer.GetTime(); | |||||
return; | return; | ||||
} | |||||
// Alt+enter toggles fullscreen | // Alt+enter toggles fullscreen | ||||
if (evt.GetKeyCode() == WXK_RETURN && wxGetKeyState(WXK_ALT)) | if (evt.GetKeyCode() == WXK_RETURN && wxGetKeyState(WXK_ALT)) | ||||
{ | { | ||||
if (m_ScenarioEditor.IsFullScreen()) | if (m_ScenarioEditor.IsFullScreen()) | ||||
m_ScenarioEditor.ShowFullScreen(false); | m_ScenarioEditor.ShowFullScreen(false); | ||||
else | else | ||||
m_ScenarioEditor.ShowFullScreen(true, wxFULLSCREEN_NOBORDER | wxFULLSCREEN_NOCAPTION); | m_ScenarioEditor.ShowFullScreen(true, wxFULLSCREEN_NOBORDER | wxFULLSCREEN_NOCAPTION); | ||||
return; | return; | ||||
} | } | ||||
if (evt.GetKeyCode() == 'c') | if (evt.GetKeyCode() == 'c') | ||||
{ | { | ||||
POST_MESSAGE(CameraReset, ()); | POST_MESSAGE(CameraReset, ()); | ||||
last_wx_user_activity = g_Timer.GetTime(); | |||||
return; | return; | ||||
} | } | ||||
int dir = 0; | int dir = 0; | ||||
if (evt.GetKeyCode() == '-' || evt.GetKeyCode() == '_') | if (evt.GetKeyCode() == '-' || evt.GetKeyCode() == '_') | ||||
dir = -1; | dir = -1; | ||||
else if (evt.GetKeyCode() == '+' || evt.GetKeyCode() == '=') | else if (evt.GetKeyCode() == '+' || evt.GetKeyCode() == '=') | ||||
dir = +1; | dir = +1; | ||||
Show All 39 Lines | virtual void HandleMouseEvent(wxMouseEvent& evt) | ||||
// e.g. brush-editing controls normally, and then move the mouse to | // e.g. brush-editing controls normally, and then move the mouse to | ||||
// see the brush outline and magically get given back full control | // see the brush outline and magically get given back full control | ||||
// of the camera. | // of the camera. | ||||
if (evt.Moving()) | if (evt.Moving()) | ||||
SetFocus(); | SetFocus(); | ||||
if (m_ScenarioEditor.GetToolManager().GetCurrentTool()->OnMouse(evt)) | if (m_ScenarioEditor.GetToolManager().GetCurrentTool()->OnMouse(evt)) | ||||
{ | { | ||||
last_wx_user_activity = g_Timer.GetTime(); | |||||
Not Done Inline ActionsThis doesn't seem to be enough. (eg panning doesn't work). Putting it out of the if works. It also restores the original behavior where you could just move the mouse around to get back your fps. Stan: This doesn't seem to be enough. (eg panning doesn't work). Putting it out of the if works. It… | |||||
Done Inline ActionsI can't test panning but I find that very odd :P That being said I can move it out, sure. wraitii: I can't test panning but I find that very odd :P
That being said I can move it out, sure. | |||||
Not Done Inline ActionsMaybe panning isn't a tool ? Which is why it's handled below ? Stan: Maybe panning isn't a tool ? Which is why it's handled below ? | |||||
// Mouse event has been handled by the tool, so don't try | // Mouse event has been handled by the tool, so don't try | ||||
// to use it for camera motion too | // to use it for camera motion too | ||||
return; | return; | ||||
} | } | ||||
// Global mouse event handlers (for camera motion) | // Global mouse event handlers (for camera motion) | ||||
if (evt.GetWheelRotation()) | if (evt.GetWheelRotation()) | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | BEGIN_EVENT_TABLE(GameCanvas, Canvas) | ||||
EVT_KEY_DOWN(GameCanvas::OnKeyDown) | EVT_KEY_DOWN(GameCanvas::OnKeyDown) | ||||
EVT_KEY_UP(GameCanvas::OnKeyUp) | EVT_KEY_UP(GameCanvas::OnKeyUp) | ||||
EVT_CHAR(GameCanvas::OnChar) | EVT_CHAR(GameCanvas::OnChar) | ||||
EVT_KILL_FOCUS(GameCanvas::OnKillFocus) | EVT_KILL_FOCUS(GameCanvas::OnKillFocus) | ||||
END_EVENT_TABLE() | END_EVENT_TABLE() | ||||
////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////// | ||||
volatile bool g_FrameHasEnded; | |||||
// Called from game thread | |||||
ATLASDLLIMPEXP void Atlas_NotifyEndOfFrame() | |||||
{ | |||||
g_FrameHasEnded = true; | |||||
} | |||||
enum | enum | ||||
{ | { | ||||
ID_Quit = 1, | ID_Quit = 1, | ||||
ID_New, | ID_New, | ||||
ID_Open, | ID_Open, | ||||
ID_Save, | ID_Save, | ||||
ID_SaveAs, | ID_SaveAs, | ||||
▲ Show 20 Lines • Show All 274 Lines • ▼ Show 20 Lines | #endif | ||||
// Wait for blank map | // Wait for blank map | ||||
qry.Post(); | qry.Post(); | ||||
POST_MESSAGE(RenderEnable, (eRenderView::GAME)); | POST_MESSAGE(RenderEnable, (eRenderView::GAME)); | ||||
// Set up a timer to make sure tool-updates happen frequently (in addition | // Set up a timer to make sure tool-updates happen frequently (in addition | ||||
// to the idle handler (which makes them happen more frequently if there's nothing | // to the idle handler (which makes them happen more frequently if there's nothing | ||||
// else to do)) | // else to do)) | ||||
m_Timer.SetOwner(this); | m_Timer.SetOwner(this, TIMER_TOOL); | ||||
m_Timer.Start(20); | m_Timer.Start(16); // in ms | ||||
Not Done Inline Actions60fps ? What about 144hz monitors ? Could be config options here and below I guess ? Stan: 60fps ? What about 144hz monitors ? Could be config options here and below I guess ? | |||||
Not Done Inline ActionsWe seem to be capped at 60fps, even when disabling VSync on Windows using D2499. For some reason though (I guess overhead) I only get 60fps if I lower it done to 4-8. You really should make it a constant, in case someone wants to change it in the future, else other places will be forgotten Source: I did :D Stan: We seem to be capped at 60fps, even when disabling VSync on Windows using D2499.
For some… | |||||
Done Inline ActionsI think the timer might have some latency yeah. I'm not sure it's a great idea to make it _too_ quick in case it starts to lag, you might have a non-rerepresentative computer and I'd rather optimise for the somewhat slower case. That said it might be doable to use a config option, I'm not sure. wraitii: I think the timer might have some latency yeah. I'm not sure it's a great idea to make it _too_… | |||||
// Set up a timer to trigger engine rendering. | |||||
// This is split from the tool timer to enable different framerates. | |||||
m_RenderTimer.SetOwner(this, TIMER_RENDER); | |||||
m_RenderTimer.Start(16); // in ms | |||||
} | } | ||||
wxToolBar* ScenarioEditor::OnCreateToolBar(long style, wxWindowID id, const wxString& WXUNUSED(name)) | wxToolBar* ScenarioEditor::OnCreateToolBar(long style, wxWindowID id, const wxString& WXUNUSED(name)) | ||||
{ | { | ||||
ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, id, style); | ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, id, style); | ||||
// TODO: configurable small vs large icon images | // TODO: configurable small vs large icon images | ||||
// (button label; tooltip text; image; internal tool name; section to switch to) | // (button label; tooltip text; image; internal tool name; section to switch to) | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | qExit().Post(); | ||||
// destroying the GLCanvas while it's still rendering | // destroying the GLCanvas while it's still rendering | ||||
Destroy(); | Destroy(); | ||||
} | } | ||||
static void UpdateTool(ToolManager& toolManager) | static void UpdateTool(ToolManager& toolManager) | ||||
{ | { | ||||
// Don't keep posting events if the game can't keep up | |||||
if (g_FrameHasEnded) | |||||
{ | |||||
g_FrameHasEnded = false; // (thread safety doesn't matter here) | |||||
// TODO: Smoother timing stuff? | // TODO: Smoother timing stuff? | ||||
static double last = g_Timer.GetTime(); | static double last = g_Timer.GetTime(); | ||||
double time = g_Timer.GetTime(); | double time = g_Timer.GetTime(); | ||||
toolManager.GetCurrentTool()->OnTick(time-last); | toolManager.GetCurrentTool()->OnTick(time-last); | ||||
last = time; | last = time; | ||||
} | } | ||||
} | |||||
void ScenarioEditor::OnTimer(wxTimerEvent&) | void ScenarioEditor::OnTimer(wxTimerEvent& evt) | ||||
{ | { | ||||
if (evt.GetId() == TIMER_TOOL) | |||||
UpdateTool(m_ToolManager); | UpdateTool(m_ToolManager); | ||||
else | |||||
{ | |||||
AtlasMessage::qRenderLoop qryRenderLoop; | |||||
qryRenderLoop.Post(); | |||||
if (!qryRenderLoop.wantHighFPS && | |||||
qryRenderLoop.timeSinceActivity > 1.0 && g_Timer.GetTime() - last_wx_user_activity > 1.0) | |||||
Not Done Inline ActionsI guess magic numbers could use constexpr or something Stan: I guess magic numbers could use constexpr or something | |||||
Not Done Inline ActionsWhy not use timer_time() Stan: Why not use timer_time() | |||||
Done Inline ActionsNot available in atlasUI. wraitii: Not available in atlasUI. | |||||
m_RenderTimer.Start(200); // Use 5 FPS to save CPU & GPU. | |||||
else | |||||
m_RenderTimer.Start(16); // Try for 60 FPS. | |||||
} | |||||
} | } | ||||
void ScenarioEditor::OnIdle(wxIdleEvent&) | void ScenarioEditor::OnIdle(wxIdleEvent&) | ||||
{ | { | ||||
UpdateTool(m_ToolManager); | UpdateTool(m_ToolManager); | ||||
} | } | ||||
void ScenarioEditor::OnQuit(wxCommandEvent&) | void ScenarioEditor::OnQuit(wxCommandEvent&) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 461 Lines • Show Last 20 Lines |
Maybe you could use enum class.