1
0
forked from 0ad/0ad

Fixed non-PCH compiles.

Removed a few global variables from Atlas.
Added call to srand(time).
Restored NotebookEvent in wxJS.
Fixed CPU-detection in Valgrind.

This was SVN commit r5318.
This commit is contained in:
Ykkrosh 2007-09-02 23:38:58 +00:00
parent fc966bcd13
commit f5a2a141dc
37 changed files with 229 additions and 115 deletions

View File

@ -2,6 +2,7 @@
#define INCLUDED_MAPWRITER
#include <vector>
#include <list>
#include "MapIO.h"
#include "ps/CStr.h"
#include "ps/FilePacker.h"

View File

@ -3,6 +3,7 @@
#include <vector>
#include <map>
#include <set>
#include "ps/CStr.h"
class CEntityTemplate;

View File

@ -12,6 +12,7 @@
#include <stdio.h>
#include <errno.h>
#include <stdarg.h>
#include "secure_crt.h"

View File

@ -14,6 +14,7 @@
#include <string.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <algorithm>
#include "lib/posix/posix.h" // pthread

View File

@ -6,6 +6,10 @@
#include <sys/sysctl.h>
#endif
#if OS_LINUX
#include "valgrind.h"
#endif
int ucpu_IsThrottlingPossible()
{
return -1; // don't know
@ -41,6 +45,12 @@ LibError ucpu_CallByEachCPU(CpuCallback cb, void* param)
{
long ncpus = sysconf(_SC_NPROCESSORS_CONF);
// Valgrind reports the number of real CPUs, but only emulates a single CPU.
// That causes problems when we expect all those CPUs to be distinct, so
// just pretend there's only one CPU
if (RUNNING_ON_VALGRIND)
ncpus = 1;
cpu_set_t set;
for (long i = 0; i < ncpus && i < CPU_SETSIZE; ++i)
{

View File

@ -14,6 +14,7 @@
#include <numeric>
#include <math.h>
#include <float.h>
#include <stdarg.h>
#include "lib/posix/posix_time.h"

View File

@ -12,6 +12,7 @@
#include "Vector3D.h"
#include <math.h>
#include <float.h>
#include "MathUtil.h"
int CVector3D::operator ! () const

View File

@ -4,6 +4,7 @@
#include <fstream>
#include <string>
#include <set>
#include <sstream>
class CLogger;
extern CLogger* g_Logger;

View File

@ -11,6 +11,7 @@
#include "FileUnpacker.h"
#include "lib/path_util.h"
#include "lib/res/res.h"
#include "ps/CStr.h"
////////////////////////////////////////////////////////////////////////////////////////
// CFileUnpacker constructor

View File

@ -898,6 +898,9 @@ void EarlyInit()
timer_Init();
cpu_Init(); // must come after timer_Init
// Initialise the low-quality rand function
srand(time(NULL));
}
void Init(const CmdLineArgs& args, uint flags)

View File

@ -17,6 +17,8 @@
#define INCLUDED_ENTITYMANAGER
#include <set>
#include <bitset>
#include <map>
#include "EntityHandles.h"
#include "ps/Game.h"
@ -25,6 +27,7 @@
class CEntityTemplate;
class CPlayer;
class CStrW;
class CStr8;
class CVector3D;
#define MAX_HANDLES 4096
@ -67,7 +70,7 @@ public:
~CEntityManager();
HEntity Create( CEntityTemplate* base, CVector3D position, float orientation,
const std::set<CStr>& actorSelections, const CStrW* building = 0 );
const std::set<CStr8>& actorSelections, const CStrW* building = 0 );
HEntity Create( const CStrW& templateName, CPlayer* player, CVector3D position,
float orientation, const CStrW* building = 0 );

View File

@ -26,7 +26,7 @@ public:
// Define RegisterFunction<TR, T0..., f>
#define OVERLOADS(z, i, data) \
template <typename TR, TYPENAME_T0_HEAD(z,i) TR (*fptr) ( T0(z,i) )> \
template <typename TR, TYPENAME_T0_HEAD(z,i) TR (*fptr) ( void* T0_TAIL(z,i) )> \
void RegisterFunction(const char* name) { \
Register(name, call<TR, T0_HEAD(z,i) fptr>, nargs<0 T0_TAIL(z,i)>()); \
}
@ -38,7 +38,7 @@ private:
// JSNative-compatible function that wraps the function identified in the template argument list
// (Definition comes later, since it depends on some things we haven't defined yet)
#define OVERLOADS(z, i, data) \
template <typename TR, TYPENAME_T0_HEAD(z,i) TR (*fptr) ( T0(z,i) )> \
template <typename TR, TYPENAME_T0_HEAD(z,i) TR (*fptr) ( void* T0_TAIL(z,i) )> \
static JSBool call(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval);
BOOST_PP_REPEAT(MAX_ARGS, OVERLOADS, ~)
#undef OVERLOADS
@ -54,7 +54,7 @@ private:
// are not permitted inside non-namespace scopes
// ScriptInterface_NativeWrapper<T>::call(cx, rval, fptr, args...) will call fptr(args),
// ScriptInterface_NativeWrapper<T>::call(cx, rval, fptr, args...) will call fptr(cbdata, args),
// and if T != void then it will store the result in rval:
// Templated on the return type so void can be handled separately
@ -63,7 +63,7 @@ struct ScriptInterface_NativeWrapper {
#define OVERLOADS(z, i, data) \
template<TYPENAME_T0_HEAD(z,i) typename f> \
static void call(JSContext* cx, jsval& rval, f fptr T0_A0(z,i)) { \
rval = ScriptInterface::ToJSVal<TR>(cx, fptr(A0(z,i))); \
rval = ScriptInterface::ToJSVal<TR>(cx, fptr(ScriptInterface::GetCallbackData(cx) A0_TAIL(z,i))); \
}
BOOST_PP_REPEAT(MAX_ARGS, OVERLOADS, ~)
@ -75,8 +75,8 @@ template <>
struct ScriptInterface_NativeWrapper<void> {
#define OVERLOADS(z, i, data) \
template<TYPENAME_T0_HEAD(z,i) typename f> \
static void call(JSContext* /*cx*/, jsval& /*rval*/, f fptr T0_A0(z,i)) { \
fptr(A0(z,i)); \
static void call(JSContext* cx, jsval& /*rval*/, f fptr T0_A0(z,i)) { \
fptr(ScriptInterface::GetCallbackData(cx) A0_TAIL(z,i)); \
}
BOOST_PP_REPEAT(MAX_ARGS, OVERLOADS, ~)
#undef OVERLOADS
@ -84,7 +84,7 @@ struct ScriptInterface_NativeWrapper<void> {
// JSNative-compatible function that wraps the function identified in the template argument list
#define OVERLOADS(z, i, data) \
template <typename TR, TYPENAME_T0_HEAD(z,i) TR (*fptr) ( T0(z,i) )> \
template <typename TR, TYPENAME_T0_HEAD(z,i) TR (*fptr) ( void* T0_TAIL(z,i) )> \
JSBool ScriptInterface::call(JSContext* cx, JSObject* /*obj*/, uintN /*argc*/, jsval* argv, jsval* rval) { \
(void)argv; /* avoid 'unused parameter' warnings */ \
BOOST_PP_REPEAT_##z (i, CONVERT_ARG, ~) \

View File

@ -11,7 +11,7 @@
#include "wx/wx.h"
#include "wxJS/common/main.h"
#include "wxJS/ext/jsmembuf.h"
#include "wxJS/ext/wxjs_ext.h"
#include "wxJS/io/init.h"
#include "wxJS/gui/init.h"
#include "wxJS/gui/control/panel.h"
@ -361,6 +361,8 @@ ScriptInterface_impl::ScriptInterface_impl()
JS_BeginRequest(m_cx); // if you get linker errors, see the comment in the .h about JS_THREADSAFE
JS_SetContextPrivate(m_cx, NULL);
JS_SetErrorReporter(m_cx, ErrorReporter);
JS_SetOptions(m_cx,
@ -375,7 +377,8 @@ ScriptInterface_impl::ScriptInterface_impl()
wxjs::gui::InitClass(m_cx, m_glob);
wxjs::io::InitClass(m_cx, m_glob);
wxjs::ext::MemoryBuffer::JSInit(m_cx, m_glob);
wxjs::ext::InitClass(m_cx, m_glob);
wxjs::ext::InitObject(m_cx, m_glob);
JS_DefineFunction(m_cx, m_glob, "print", ::print, 0, JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT);
@ -423,6 +426,16 @@ ScriptInterface::~ScriptInterface()
{
}
void ScriptInterface::SetCallbackData(void* cbdata)
{
JS_SetContextPrivate(m->m_cx, cbdata);
}
void* ScriptInterface::GetCallbackData(JSContext* cx)
{
return JS_GetContextPrivate(cx);
}
void ScriptInterface::Register(const char* name, JSNative fptr, size_t nargs)
{
m->Register(name, fptr, (uintN)nargs);

View File

@ -26,9 +26,11 @@ class ScriptInterface
public:
ScriptInterface();
~ScriptInterface();
void SetCallbackData(void* cbdata);
static void* GetCallbackData(JSContext* cx);
// Defined elsewhere:
// template <TR, T0..., TR (*fptr) (T0...)>
// template <TR, T0..., TR (*fptr) (void* cbdata, T0...)>
// void RegisterFunction(const char* functionName);
// (NOTE: The return type must be defined as a ToJSVal<TR> specialisation
// in ScriptInterface.cpp, else you'll end up with linker errors.)

View File

@ -7,6 +7,7 @@
#include "ToolButton.h"
#include "ScenarioEditor/Tools/Common/Tools.h"
#include "ScenarioEditor/SectionLayout.h"
#include "General/Datafile.h"
BEGIN_EVENT_TABLE(ToolButton, wxButton)
@ -14,13 +15,10 @@ BEGIN_EVENT_TABLE(ToolButton, wxButton)
END_EVENT_TABLE()
ToolButton::ToolButton
(wxWindow *parent,
const wxString& label,
const wxString& toolName,
const wxSize& size,
long style)
: wxButton(parent, wxID_ANY, label, wxDefaultPosition, size, style),
m_Tool(toolName)
(ToolManager& toolManager, wxWindow *parent, const wxString& label, const wxString& toolName, const wxSize& size, long style)
: wxButton(parent, wxID_ANY, label, wxDefaultPosition, size, style)
, m_ToolManager(toolManager)
, m_Tool(toolName)
{
// Explicitly set appearance, so that the button is always owner-drawn
// (by the wxButton code), rather than initially using the native
@ -34,9 +32,9 @@ void ToolButton::OnClick(wxCommandEvent& WXUNUSED(evt))
{
// Toggle on/off
if (m_Selected)
SetCurrentTool(_T(""));
m_ToolManager.SetCurrentTool(_T(""));
else
SetCurrentTool(m_Tool);
m_ToolManager.SetCurrentTool(m_Tool);
}
void ToolButton::SetSelectedAppearance(bool selected)
@ -54,9 +52,9 @@ BEGIN_EVENT_TABLE(ToolButtonBar, wxToolBar)
EVT_TOOL(wxID_ANY, ToolButtonBar::OnTool)
END_EVENT_TABLE()
ToolButtonBar::ToolButtonBar(wxWindow* parent, SectionLayout* sectionLayout, int baseID)
ToolButtonBar::ToolButtonBar(ToolManager& toolManager, wxWindow* parent, SectionLayout* sectionLayout, int baseID)
: wxToolBar(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTB_FLAT|wxTB_HORIZONTAL)
, m_SectionLayout(sectionLayout), m_Id(baseID), m_Size(-1)
, m_ToolManager(toolManager), m_SectionLayout(sectionLayout), m_Id(baseID), m_Size(-1)
{
/* "msw.remap: If 1 (the default), wxToolBar bitmap colours will be remapped
to the current theme's values. Set this to 0 to disable this functionality,
@ -105,7 +103,7 @@ void ToolButtonBar::OnTool(wxCommandEvent& evt)
{
std::map<int, Button>::iterator it = m_Buttons.find(evt.GetId());
wxCHECK_RET(it != m_Buttons.end(), _T("Invalid toolbar button"));
SetCurrentTool(it->second.name);
m_ToolManager.SetCurrentTool(it->second.name);
if (! it->second.sectionPage.IsEmpty())
m_SectionLayout->SelectPage(it->second.sectionPage);
}

View File

@ -4,11 +4,12 @@
class ITool;
class SectionLayout;
class ToolManager;
class ToolButton : public wxButton
{
public:
ToolButton(wxWindow *parent, const wxString& label, const wxString& toolName, const wxSize& size = wxDefaultSize, long style = 0);
ToolButton(ToolManager& toolManager, wxWindow *parent, const wxString& label, const wxString& toolName, const wxSize& size = wxDefaultSize, long style = 0);
void SetSelectedAppearance(bool selected);
@ -16,6 +17,7 @@ protected:
void OnClick(wxCommandEvent& evt);
private:
ToolManager& m_ToolManager;
wxString m_Tool;
bool m_Selected;
@ -25,7 +27,7 @@ private:
class ToolButtonBar : public wxToolBar
{
public:
ToolButtonBar(wxWindow* parent, SectionLayout* sectionLayout, int baseID);
ToolButtonBar(ToolManager& toolManager, wxWindow* parent, SectionLayout* sectionLayout, int baseID);
void AddToolButton(const wxString& shortLabel, const wxString& longLabel,
const wxString& iconPNGFilename, const wxString& toolName, const wxString& sectionPage);
@ -33,6 +35,7 @@ protected:
void OnTool(wxCommandEvent& evt);
private:
ToolManager& m_ToolManager;
int m_Id;
int m_Size;
struct Button

View File

@ -50,9 +50,9 @@ ATLASDLLIMPEXP void Atlas_GLSwapBuffers(void* canvas)
class GameCanvas : public Canvas
{
public:
GameCanvas(wxWindow* parent, int* attribList)
GameCanvas(ToolManager& toolManager, wxWindow* parent, int* attribList)
: Canvas(parent, attribList, wxWANTS_CHARS),
m_MouseState(NONE), m_LastMouseState(NONE)
m_ToolManager(toolManager), m_MouseState(NONE), m_LastMouseState(NONE)
{
}
@ -90,7 +90,7 @@ private:
void OnKeyDown(wxKeyEvent& evt)
{
if (GetCurrentTool().OnKey(evt, ITool::KEY_DOWN))
if (m_ToolManager.GetCurrentTool().OnKey(evt, ITool::KEY_DOWN))
{
// Key event has been handled by the tool, so don't try
// to use it for camera motion too
@ -105,7 +105,7 @@ private:
void OnKeyUp(wxKeyEvent& evt)
{
if (GetCurrentTool().OnKey(evt, ITool::KEY_UP))
if (m_ToolManager.GetCurrentTool().OnKey(evt, ITool::KEY_UP))
return;
if (KeyScroll(evt, false))
@ -116,7 +116,7 @@ private:
void OnChar(wxKeyEvent& evt)
{
if (GetCurrentTool().OnKey(evt, ITool::KEY_CHAR))
if (m_ToolManager.GetCurrentTool().OnKey(evt, ITool::KEY_CHAR))
return;
int dir = 0;
@ -151,7 +151,7 @@ private:
if (evt.Moving())
SetFocus();
if (GetCurrentTool().OnMouse(evt))
if (m_ToolManager.GetCurrentTool().OnMouse(evt))
{
// Mouse event has been handled by the tool, so don't try
// to use it for camera motion too
@ -204,6 +204,8 @@ private:
enum { NONE, SCROLL, ROTATEAROUND };
int m_MouseState, m_LastMouseState;
ToolManager& m_ToolManager;
DECLARE_EVENT_TABLE();
};
@ -267,17 +269,21 @@ AtlasWindowCommandProc& ScenarioEditor::GetCommandProc() { return g_CommandProc;
namespace
{
// Wrapper function because SetCurrentTool takes an optional argument, which JS doesn't like
void SetCurrentTool_script(wxString name)
void SetCurrentTool_script(void* cbdata, wxString name)
{
SetCurrentTool(name);
static_cast<ScenarioEditor*>(cbdata)->GetToolManager().SetCurrentTool(name);
}
wxString GetDataDirectory(void*)
{
return Datafile::GetDataDirectory();
}
// TODO: see comment in terrain.js, and remove this when/if it's no longer necessary
void SetBrushStrength(float strength)
void SetBrushStrength(void*, float strength)
{
g_Brush_Elevation.SetStrength(strength);
}
void SetSelectedTexture(wxString name)
void SetSelectedTexture(void*, wxString name)
{
g_SelectedTexture = name;
}
@ -286,6 +292,8 @@ namespace
ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterface)
: wxFrame(parent, wxID_ANY, _T(""), wxDefaultPosition, wxSize(1024, 768))
, m_FileHistory(_T("Scenario Editor")), m_ScriptInterface(scriptInterface)
, m_ObjectSettings(g_SelectedObjects, AtlasMessage::eRenderView::GAME)
, m_ToolManager(this)
{
// Global application initialisation:
@ -301,7 +309,8 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterfac
//////////////////////////////////////////////////////////////////////////
// Script interface functions
GetScriptInterface().RegisterFunction<wxString, Datafile::GetDataDirectory>("GetDataDirectory");
GetScriptInterface().SetCallbackData(static_cast<void*>(this));
GetScriptInterface().RegisterFunction<wxString, GetDataDirectory>("GetDataDirectory");
GetScriptInterface().RegisterFunction<void, wxString, SetCurrentTool_script>("SetCurrentTool");
GetScriptInterface().RegisterFunction<void, float, SetBrushStrength>("SetBrushStrength");
GetScriptInterface().RegisterFunction<void, wxString, SetSelectedTexture>("SetSelectedTexture");
@ -366,7 +375,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterfac
// Toolbar:
ToolButtonBar* toolbar = new ToolButtonBar(this, &m_SectionLayout, ID_Toolbar);
ToolButtonBar* toolbar = new ToolButtonBar(m_ToolManager, this, &m_SectionLayout, ID_Toolbar);
// TODO: configurable small vs large icon images
// (button label; tooltip text; image; internal tool name; section to switch to)
@ -379,7 +388,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterfac
toolbar->Realize();
SetToolBar(toolbar);
// Set the default tool to be selected
SetCurrentTool(_T(""));
m_ToolManager.SetCurrentTool(_T(""));
// Set up GL canvas:
@ -392,7 +401,7 @@ ScenarioEditor::ScenarioEditor(wxWindow* parent, ScriptInterface& scriptInterfac
WX_GL_MIN_ALPHA, 8, // alpha bits
0
};
Canvas* canvas = new GameCanvas(m_SectionLayout.GetCanvasParent(), glAttribList);
Canvas* canvas = new GameCanvas(m_ToolManager, m_SectionLayout.GetCanvasParent(), glAttribList);
m_SectionLayout.SetCanvas(canvas);
// Set up sidebars:
@ -453,7 +462,7 @@ float ScenarioEditor::GetSpeedModifier()
void ScenarioEditor::OnClose(wxCloseEvent&)
{
SetCurrentTool(_T(""));
m_ToolManager.SetCurrentTool(_T(""));
m_FileHistory.Save(*wxConfigBase::Get());
@ -467,7 +476,7 @@ void ScenarioEditor::OnClose(wxCloseEvent&)
}
static void UpdateTool()
static void UpdateTool(ToolManager& toolManager)
{
// Don't keep posting events if the game can't keep up
if (g_FrameHasEnded)
@ -476,17 +485,17 @@ static void UpdateTool()
// TODO: Smoother timing stuff?
static double last = g_Timer.GetTime();
double time = g_Timer.GetTime();
GetCurrentTool().OnTick(time-last);
toolManager.GetCurrentTool().OnTick(time-last);
last = time;
}
}
void ScenarioEditor::OnTimer(wxTimerEvent&)
{
UpdateTool();
UpdateTool(m_ToolManager);
}
void ScenarioEditor::OnIdle(wxIdleEvent&)
{
UpdateTool();
UpdateTool(m_ToolManager);
}
void ScenarioEditor::OnQuit(wxCommandEvent&)
@ -516,7 +525,7 @@ void ScenarioEditor::OpenFile(const wxString& name)
// Deactivate tools, so they don't carry forwards into the new CWorld
// and crash.
SetCurrentTool(_T(""));
m_ToolManager.SetCurrentTool(_T(""));
// TODO: clear the undo buffer, etc
POST_MESSAGE(LoadMap, (map));
@ -569,7 +578,7 @@ void ScenarioEditor::OnSave(wxCommandEvent& event)
// Deactivate tools, so things like unit previews don't get saved.
// (TODO: Would be nicer to leave the tools active, and just not save
// the preview units.)
SetCurrentTool(_T(""));
m_ToolManager.SetCurrentTool(_T(""));
std::wstring map = m_OpenFilename.c_str();
POST_MESSAGE(SaveMap, (map));
@ -591,7 +600,7 @@ void ScenarioEditor::OnSaveAs(wxCommandEvent& WXUNUSED(event))
{
wxBusyInfo busy(_("Saving map"));
SetCurrentTool(_T(""));
m_ToolManager.SetCurrentTool(_T(""));
// TODO: Work when the map is not in .../maps/scenarios/
std::wstring map = dlg.GetFilename().c_str();

View File

@ -2,6 +2,9 @@
#define INCLUDED_SCENARIOEDITOR
#include "General/AtlasWindowCommandProc.h"
#include "General/Observable.h"
#include "Tools/Common/ObjectSettings.h"
#include "Tools/Common/Tools.h"
#include "CustomControls/FileHistory/FileHistory.h"
#include "SectionLayout.h"
@ -38,14 +41,21 @@ public:
static float GetSpeedModifier();
ScriptInterface& GetScriptInterface() const { return m_ScriptInterface; }
Observable<ObjectSettings>& GetObjectSettings() { return m_ObjectSettings; }
ToolManager& GetToolManager() { return m_ToolManager; }
private:
ScriptInterface& m_ScriptInterface;
ToolManager m_ToolManager;
wxTimer m_Timer;
SectionLayout m_SectionLayout;
Observable<ObjectSettings> m_ObjectSettings;
void SetOpenFilename(const wxString& filename);
wxString m_OpenFilename;
FileHistory m_FileHistory;

View File

@ -6,7 +6,7 @@
#include "CustomControls/Buttons/ActionButton.h"
//#include "CustomControls/Buttons/FloatingSpinCtrl.h"
#include "General/Datafile.h"
#include "ScenarioEditor/Tools/Common/Tools.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "HighResTimer/HighResTimer.h"
#include "General/VideoRecorder/VideoRecorder.h"

View File

@ -4,7 +4,7 @@
#include "LightControl.h"
#include "GameInterface/Messages.h"
#include "ScenarioEditor/Tools/Common/Tools.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "General/Observable.h"
#include "CustomControls/ColourDialog/ColourDialog.h"

View File

@ -3,7 +3,7 @@
#include "Object.h"
#include "Buttons/ToolButton.h"
#include "ScenarioEditor/Tools/Common/Tools.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "ScenarioEditor/Tools/Common/ObjectSettings.h"
#include "ScenarioEditor/Tools/Common/MiscState.h"
#include "VariationControl.h"
@ -15,8 +15,9 @@
class ObjectSelectListBox : public wxListBox
{
public:
ObjectSelectListBox(wxWindow* parent)
ObjectSelectListBox(wxWindow* parent, ToolManager& toolManager)
: wxListBox(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE|wxLB_HSCROLL)
, m_ToolManager(toolManager)
{
}
@ -24,10 +25,11 @@ public:
{
// On selecting an object, enable the PlaceObject tool with this object
wxString id = static_cast<wxStringClientData*>(evt.GetClientObject())->GetData();
SetCurrentTool(_T("PlaceObject"), &id);
m_ToolManager.SetCurrentTool(_T("PlaceObject"), &id);
}
private:
ToolManager& m_ToolManager;
DECLARE_EVENT_TABLE();
};
BEGIN_EVENT_TABLE(ObjectSelectListBox, wxListBox)
@ -66,7 +68,7 @@ END_EVENT_TABLE();
class ObjectBottomBar : public wxPanel
{
public:
ObjectBottomBar(wxWindow* parent);
ObjectBottomBar(wxWindow* parent, Observable<ObjectSettings>& objectSettings);
};
struct ObjectSidebarImpl
@ -85,10 +87,10 @@ ObjectSidebar::ObjectSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebarCo
strings.Add(_("Actors (all)"));
m_MainSizer->Add(new ObjectChoiceCtrl(this, strings, *this), wxSizerFlags().Expand());
p->m_ObjectListBox = new ObjectSelectListBox(this);
p->m_ObjectListBox = new ObjectSelectListBox(this, scenarioEditor.GetToolManager());
m_MainSizer->Add(p->m_ObjectListBox, wxSizerFlags().Proportion(1).Expand());
m_BottomBar = new ObjectBottomBar(bottomBarContainer);
m_BottomBar = new ObjectBottomBar(bottomBarContainer, scenarioEditor.GetObjectSettings());
}
ObjectSidebar::~ObjectSidebar()
@ -129,20 +131,17 @@ void ObjectSidebar::SetObjectFilter(int type)
class PlayerComboBox : public wxComboBox
{
public:
PlayerComboBox(wxWindow* parent, wxArrayString& choices)
: wxComboBox(parent, -1, choices[g_ObjectSettings.GetPlayerID()], wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY)
PlayerComboBox(wxWindow* parent, wxArrayString& choices, Observable<ObjectSettings>& objectSettings)
: wxComboBox(parent, -1, choices[objectSettings.GetPlayerID()], wxDefaultPosition, wxDefaultSize, choices, wxCB_READONLY)
, m_ObjectSettings(objectSettings)
{
m_Conn = g_ObjectSettings.RegisterObserver(1, &PlayerComboBox::OnObjectSettingsChange, this);
}
~PlayerComboBox()
{
g_ObjectSettings.RemoveObserver(m_Conn);
m_Conn = m_ObjectSettings.RegisterObserver(1, &PlayerComboBox::OnObjectSettingsChange, this);
}
private:
ObservableConnection m_Conn;
ObservableScopedConnection m_Conn;
Observable<ObjectSettings>& m_ObjectSettings;
void OnObjectSettingsChange(const ObjectSettings& settings)
{
@ -151,8 +150,8 @@ private:
void OnSelect(wxCommandEvent& evt)
{
g_ObjectSettings.SetPlayerID(evt.GetInt());
g_ObjectSettings.NotifyObserversExcept(m_Conn);
m_ObjectSettings.SetPlayerID(evt.GetInt());
m_ObjectSettings.NotifyObserversExcept(m_Conn);
}
DECLARE_EVENT_TABLE();
@ -163,7 +162,7 @@ END_EVENT_TABLE();
//////////////////////////////////////////////////////////////////////////
ObjectBottomBar::ObjectBottomBar(wxWindow* parent)
ObjectBottomBar::ObjectBottomBar(wxWindow* parent, Observable<ObjectSettings>& objectSettings)
: wxPanel(parent, wxID_ANY)
{
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
@ -179,10 +178,10 @@ ObjectBottomBar::ObjectBottomBar(wxWindow* parent)
players.Add(_("Player 6"));
players.Add(_("Player 7"));
players.Add(_("Player 8"));
wxComboBox* playerSelect = new PlayerComboBox(this, players);
wxComboBox* playerSelect = new PlayerComboBox(this, players, objectSettings);
sizer->Add(playerSelect);
wxWindow* variationSelect = new VariationControl(this, g_ObjectSettings);
wxWindow* variationSelect = new VariationControl(this, objectSettings);
variationSelect->SetMinSize(wxSize(160, -1));
wxSizer* variationSizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Variation"));
variationSizer->Add(variationSelect, wxSizerFlags().Proportion(1).Expand());

View File

@ -4,8 +4,8 @@
#include "Buttons/ToolButton.h"
#include "General/Datafile.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "ScenarioEditor/Tools/Common/Brushes.h"
#include "ScenarioEditor/Tools/Common/Tools.h"
#include "ScenarioEditor/Tools/Common/MiscState.h"
#include "GameInterface/Messages.h"
@ -38,11 +38,11 @@ TerrainSidebar::TerrainSidebar(ScenarioEditor& scenarioEditor, wxWindow* sidebar
{
wxSizer* sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Elevation tools"));
sizer->Add(new ToolButton(this, _("Modify"), _T("AlterElevation"), wxSize(50,20)));
sizer->Add(new ToolButton(this, _("Flatten"), _T("FlattenElevation"), wxSize(50,20)));
// sizer->Add(new ToolButton(this, _("Smooth"), _T(""), wxSize(50,20)));
// sizer->Add(new ToolButton(this, _("Sample"), _T(""), wxSize(50,20)));
sizer->Add(new ToolButton(this, _("Paint"), _T("PaintTerrain"), wxSize(50,20)));
sizer->Add(new ToolButton(scenarioEditor.GetToolManager(), this, _("Modify"), _T("AlterElevation"), wxSize(50,20)));
sizer->Add(new ToolButton(scenarioEditor.GetToolManager(), this, _("Flatten"), _T("FlattenElevation"), wxSize(50,20)));
// sizer->Add(new ToolButton(scenarioEditor.GetToolManager(), this, _("Smooth"), _T(""), wxSize(50,20)));
// sizer->Add(new ToolButton(scenarioEditor.GetToolManager(), this, _("Sample"), _T(""), wxSize(50,20)));
sizer->Add(new ToolButton(scenarioEditor.GetToolManager(), this, _("Paint"), _T("PaintTerrain"), wxSize(50,20)));
m_MainSizer->Add(sizer);
}

View File

@ -3,7 +3,7 @@
#include "Trigger.h"
#include "GameInterface/Messages.h"
#include "CustomControls/Buttons/ActionButton.h"
#include "ScenarioEditor/Tools/Common/Tools.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "ScenarioEditor/Tools/Common/MiscState.h"
#include "wx/treectrl.h"

View File

@ -1,5 +1,6 @@
#include "precompiled.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "Common/Tools.h"
#include "Common/Brushes.h"
#include "GameInterface/Messages.h"

View File

@ -3,9 +3,7 @@
#include "ObjectSettings.h"
#include "GameInterface/Messages.h"
#include "ScenarioEditor/Tools/Common/Tools.h"
Observable<ObjectSettings> g_ObjectSettings(g_SelectedObjects, AtlasMessage::eRenderView::GAME);
#include "ScenarioEditor/ScenarioEditor.h"
ObjectSettings::ObjectSettings(Observable<std::vector<AtlasMessage::ObjectID> >& selectedObjects, int view)
: m_PlayerID(0), m_SelectedObjects(selectedObjects), m_View(view)

View File

@ -60,6 +60,4 @@ private:
void PostToGame();
};
extern Observable<ObjectSettings> g_ObjectSettings;
#endif // INCLUDED_OBJECTSETTINGS

View File

@ -6,33 +6,49 @@
class DummyTool : public ITool
{
void Init(void*) {}
void Init(void*, ScenarioEditor*) {}
void Shutdown() {}
bool OnMouse(wxMouseEvent& WXUNUSED(evt)) { return false; }
bool OnKey(wxKeyEvent& WXUNUSED(evt), KeyEventType) { return false; }
void OnTick(float) {}
} dummy;
static ITool* g_CurrentTool = &dummy;
static wxString g_CurrentToolName;
struct ToolManagerImpl
{
ToolManagerImpl() : CurrentTool(&dummy) {}
ITool* CurrentTool;
wxString CurrentToolName;
};
ToolManager::ToolManager(ScenarioEditor* scenarioEditor)
: m(new ToolManagerImpl), m_ScenarioEditor(scenarioEditor)
{
}
ToolManager::~ToolManager()
{
delete m;
}
ITool& ToolManager::GetCurrentTool()
{
return *m->CurrentTool;
}
void SetActive(bool active, const wxString& name);
ITool& GetCurrentTool()
void ToolManager::SetCurrentTool(const wxString& name, void* initData)
{
return *g_CurrentTool;
}
void SetCurrentTool(const wxString& name, void* initData)
{
if (g_CurrentTool != &dummy)
if (m->CurrentTool != &dummy)
{
g_CurrentTool->Shutdown();
delete g_CurrentTool;
g_CurrentTool = &dummy;
m->CurrentTool->Shutdown();
delete m->CurrentTool;
m->CurrentTool = &dummy;
}
SetActive(false, g_CurrentToolName);
SetActive(false, m->CurrentToolName);
ITool* tool = NULL;
if (name.Len())
@ -43,12 +59,12 @@ void SetCurrentTool(const wxString& name, void* initData)
if (tool)
{
g_CurrentTool = tool;
tool->Init(initData);
m->CurrentTool = tool;
tool->Init(initData, m_ScenarioEditor);
}
g_CurrentToolName = name;
SetActive(true, g_CurrentToolName);
m->CurrentToolName = name;
SetActive(true, m->CurrentToolName);
}
//////////////////////////////////////////////////////////////////////////

View File

@ -1,18 +1,18 @@
#ifndef INCLUDED_TOOLS
#define INCLUDED_TOOLS
#include "ScenarioEditor/ScenarioEditor.h"
#include "General/AtlasWindowCommand.h"
class wxMouseEvent;
class wxKeyEvent;
class ScenarioEditor;
class ITool : public wxObject
{
public:
enum KeyEventType { KEY_DOWN, KEY_UP, KEY_CHAR };
virtual void Init(void* initData) = 0;
virtual void Init(void* initData, ScenarioEditor* scenarioEditor) = 0;
virtual void Shutdown() = 0;
virtual bool OnMouse(wxMouseEvent& evt) = 0; // return true if handled
virtual bool OnKey(wxKeyEvent& evt, KeyEventType dir) = 0; // return true if handled
@ -21,8 +21,18 @@ public:
virtual ~ITool() {};
};
extern ITool& GetCurrentTool();
extern void SetCurrentTool(const wxString& name, void* initData = NULL);
struct ToolManagerImpl;
class ToolManager
{
public:
ToolManager(ScenarioEditor* scenarioEditor);
~ToolManager();
ITool& GetCurrentTool();
void SetCurrentTool(const wxString& name, void* initData = NULL);
private:
ToolManagerImpl* m;
ScenarioEditor* m_ScenarioEditor;
};
class ToolButton;
extern void RegisterToolButton(ToolButton* button, const wxString& toolName);
@ -59,12 +69,13 @@ class StateDrivenTool : public ITool
{
public:
StateDrivenTool()
: m_CurrentState(&Disabled)
: m_CurrentState(&Disabled), m_ScenarioEditor(NULL)
{
}
virtual void Init(void* WXUNUSED(initData))
virtual void Init(void* WXUNUSED(initData), ScenarioEditor* scenarioEditor)
{
m_ScenarioEditor = scenarioEditor;
}
virtual void Shutdown()
@ -110,9 +121,13 @@ protected:
m_CurrentState->OnEnter(static_cast<T*>(this));
}
ScenarioEditor& GetScenarioEditor() { wxASSERT(m_ScenarioEditor); return *m_ScenarioEditor; }
private:
State* m_CurrentState;
ScenarioEditor* m_ScenarioEditor; // not NULL, except before Init has been called
virtual bool OnMouse(wxMouseEvent& evt)
{
return m_CurrentState->OnMouse(static_cast<T*>(this), evt);

View File

@ -1,5 +1,6 @@
#include "precompiled.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "Common/Tools.h"
#include "Common/Brushes.h"
#include "GameInterface/Messages.h"

View File

@ -1,5 +1,6 @@
#include "precompiled.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "Common/Tools.h"
#include "Common/Brushes.h"
#include "Common/MiscState.h"

View File

@ -1,5 +1,6 @@
#include "precompiled.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "Common/Tools.h"
#include "Common/Brushes.h"
#include "Common/MiscState.h"
@ -30,13 +31,15 @@ public:
+ (m_ScreenPos.type1.y-m_Target.type1.y)*(m_ScreenPos.type1.y-m_Target.type1.y);
bool useTarget = (dragDistSq >= 16*16);
if (preview)
POST_MESSAGE(ObjectPreview, (m_ObjectID.c_str(), g_ObjectSettings.GetSettings(), m_ObjPos, useTarget, m_Target, g_DefaultAngle));
POST_MESSAGE(ObjectPreview, (m_ObjectID.c_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), m_ObjPos, useTarget, m_Target, g_DefaultAngle));
else
POST_COMMAND(CreateObject, (m_ObjectID.c_str(), g_ObjectSettings.GetSettings(), m_ObjPos, useTarget, m_Target, g_DefaultAngle));
POST_COMMAND(CreateObject, (m_ObjectID.c_str(), GetScenarioEditor().GetObjectSettings().GetSettings(), m_ObjPos, useTarget, m_Target, g_DefaultAngle));
}
virtual void Init(void* initData)
virtual void Init(void* initData, ScenarioEditor* scenarioEditor)
{
StateDrivenTool<PlaceObject>::Init(initData, scenarioEditor);
wxASSERT(initData);
wxString& id = *static_cast<wxString*>(initData);
m_ObjectID = id;
@ -134,8 +137,8 @@ public:
if (type == KEY_CHAR && (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9'))
{
int playerID = evt.GetKeyCode() - '0';
g_ObjectSettings.SetPlayerID(playerID);
g_ObjectSettings.NotifyObservers();
obj->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerID);
obj->GetScenarioEditor().GetObjectSettings().NotifyObservers();
obj->SendObjectMsg(true);
return true;
}

View File

@ -1,5 +1,6 @@
#include "precompiled.h"
#include "ScenarioEditor/ScenarioEditor.h"
#include "Common/Tools.h"
#include "Common/Brushes.h"
#include "Common/MiscState.h"
@ -77,7 +78,7 @@ public:
return false;
}
bool OnKey(TransformObject* WXUNUSED(obj), wxKeyEvent& evt, KeyEventType type)
bool OnKey(TransformObject* obj, wxKeyEvent& evt, KeyEventType type)
{
if (type == KEY_CHAR && evt.GetKeyCode() == WXK_DELETE)
{
@ -93,8 +94,8 @@ public:
else if (type == KEY_CHAR && (evt.GetKeyCode() >= '0' && evt.GetKeyCode() <= '9'))
{
int playerID = evt.GetKeyCode() - '0';
g_ObjectSettings.SetPlayerID(playerID);
g_ObjectSettings.NotifyObservers();
obj->GetScenarioEditor().GetObjectSettings().SetPlayerID(playerID);
obj->GetScenarioEditor().GetObjectSettings().NotifyObservers();
return true;
}
else

View File

@ -5,6 +5,7 @@
#include "../CommandProc.h"
#include "graphics/Terrain.h"
#include "ps/CStr.h"
#include "ps/Game.h"
#include "ps/World.h"
#include "maths/MathUtil.h"

View File

@ -1,9 +1,14 @@
#ifndef SIMSTATE_INCLUDED
#define SIMSTATE_INCLUDED
#include <set>
#include <vector>
#include "ps/CStr.h"
#include "maths/Vector3D.h"
class CUnit;
class CEntity;
#include "maths/Vector3D.h"
class SimState
{

View File

@ -1,6 +1,8 @@
#ifndef INCLUDED_VIEW
#define INCLUDED_VIEW
#include <map>
#include "graphics/Camera.h"
#include "Messages.h"

View File

@ -56,4 +56,12 @@ gui/gui_init.cpp: add
obj = Timer::JSInit(cx, global);
wxASSERT_MSG(obj != NULL, wxT("wxTimer prototype creation failed"));
if (! obj )
return false;
return false;
gui/event/jsevent.cpp: add
obj = NotebookEvent::JSInit(cx, global, NotifyEvent::GetClassPrototype());
wxASSERT_MSG(obj != NULL, wxT("wxNotebookEvent prototype creation failed"));
if (! obj )
return false;
TODO: add back tooltips into window.cpp

View File

@ -48,6 +48,7 @@
#include "htmllink.h"
#include "split.h"
#include "spinevt.h"
#include "notebookevt.h"
#include "notify.h"
#include "listevt.h"
@ -178,5 +179,10 @@ bool wxjs::gui::InitEventClasses(JSContext *cx, JSObject *global)
if (! obj )
return false;
obj = NotebookEvent::JSInit(cx, global, NotifyEvent::GetClassPrototype());
wxASSERT_MSG(obj != NULL, wxT("wxNotebookEvent prototype creation failed"));
if (! obj )
return false;
return true;
}