ScEd: allowed creation of non-entity objects, pending total entitisation
This was SVN commit r2085.
This commit is contained in:
parent
b07d9954e0
commit
8b12c84df7
@ -8,6 +8,13 @@
|
|||||||
#include "VFSUtil.h"
|
#include "VFSUtil.h"
|
||||||
#include "ObjectBase.h"
|
#include "ObjectBase.h"
|
||||||
#include "ObjectEntry.h"
|
#include "ObjectEntry.h"
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "EntityManager.h"
|
||||||
|
#include "BaseEntity.h"
|
||||||
|
#include "Game.h"
|
||||||
|
#include "Model.h"
|
||||||
|
#include "Unit.h"
|
||||||
|
#include "Matrix3D.h"
|
||||||
|
|
||||||
#define LOG_CATEGORY "graphics"
|
#define LOG_CATEGORY "graphics"
|
||||||
|
|
||||||
@ -21,7 +28,7 @@ bool operator< (const CObjectManager::ObjectKey& a, const CObjectManager::Object
|
|||||||
return a.ActorVariation < b.ActorVariation;
|
return a.ActorVariation < b.ActorVariation;
|
||||||
}
|
}
|
||||||
|
|
||||||
CObjectManager::CObjectManager() : m_SelectedEntity(NULL)
|
CObjectManager::CObjectManager() : m_SelectedThing(NULL)
|
||||||
{
|
{
|
||||||
m_ObjectTypes.reserve(32);
|
m_ObjectTypes.reserve(32);
|
||||||
}
|
}
|
||||||
@ -152,3 +159,82 @@ void CObjectManager::LoadObjects()
|
|||||||
{
|
{
|
||||||
AddObjectType("");
|
AddObjectType("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void GetObjectThunk(const char* path, const vfsDirEnt* ent, void* context)
|
||||||
|
{
|
||||||
|
std::vector<CStr>* names = (std::vector<CStr>*)context;
|
||||||
|
CStr name (path);
|
||||||
|
names->push_back(name.AfterFirst("actors/"));
|
||||||
|
}
|
||||||
|
void CObjectManager::GetAllObjectNames(std::vector<CStr>& names)
|
||||||
|
{
|
||||||
|
VFSUtil::EnumDirEnts("art/actors/", "*.xml", true, GetObjectThunk, &names);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct CObjectThing_Entity : public CObjectThing
|
||||||
|
{
|
||||||
|
CObjectThing_Entity(CBaseEntity* b) : base(b) {}
|
||||||
|
~CObjectThing_Entity() {}
|
||||||
|
CBaseEntity* base;
|
||||||
|
CEntity* ent;
|
||||||
|
void Create(CMatrix3D& transform, int playerID)
|
||||||
|
{
|
||||||
|
CVector3D orient = transform.GetIn();
|
||||||
|
CVector3D position = transform.GetTranslation();
|
||||||
|
ent = g_EntityManager.create(base, position, atan2(-orient.X, -orient.Z));
|
||||||
|
ent->SetPlayer(g_Game->GetPlayer(playerID));
|
||||||
|
}
|
||||||
|
void SetTransform(CMatrix3D& transform)
|
||||||
|
{
|
||||||
|
CVector3D orient = transform.GetIn();
|
||||||
|
CVector3D position = transform.GetTranslation();
|
||||||
|
|
||||||
|
// This is quite yucky, but nothing else seems to actually work:
|
||||||
|
ent->m_position =
|
||||||
|
ent->m_position_previous =
|
||||||
|
ent->m_graphics_position = position;
|
||||||
|
ent->teleport();
|
||||||
|
ent->m_orientation =
|
||||||
|
ent->m_orientation_previous =
|
||||||
|
ent->m_graphics_orientation = atan2(-orient.X, -orient.Z);
|
||||||
|
ent->reorient();
|
||||||
|
}
|
||||||
|
CObjectEntry* GetObjectEntry()
|
||||||
|
{
|
||||||
|
return g_ObjMan.FindObject((CStr)base->m_actorName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct CObjectThing_Object : public CObjectThing
|
||||||
|
{
|
||||||
|
CObjectThing_Object(CObjectEntry* o) : obj(o) {}
|
||||||
|
~CObjectThing_Object() {}
|
||||||
|
CObjectEntry* obj;
|
||||||
|
CUnit* unit;
|
||||||
|
void Create(CMatrix3D& transform, int playerID)
|
||||||
|
{
|
||||||
|
unit = new CUnit(obj, obj->m_Model->Clone());
|
||||||
|
unit->GetModel()->SetTransform(transform);
|
||||||
|
g_UnitMan.AddUnit(unit);
|
||||||
|
}
|
||||||
|
void SetTransform(CMatrix3D& transform)
|
||||||
|
{
|
||||||
|
unit->GetModel()->SetTransform(transform);
|
||||||
|
}
|
||||||
|
CObjectEntry* GetObjectEntry()
|
||||||
|
{
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void CObjectManager::SetSelectedEntity(CBaseEntity* thing)
|
||||||
|
{
|
||||||
|
delete m_SelectedThing;
|
||||||
|
m_SelectedThing = (thing ? new CObjectThing_Entity(thing) : NULL);
|
||||||
|
}
|
||||||
|
void CObjectManager::SetSelectedObject(CObjectEntry* thing)
|
||||||
|
{
|
||||||
|
delete m_SelectedThing;
|
||||||
|
m_SelectedThing = (thing ? new CObjectThing_Object(thing) : NULL);
|
||||||
|
}
|
||||||
|
@ -10,10 +10,21 @@
|
|||||||
class CObjectBase;
|
class CObjectBase;
|
||||||
class CObjectEntry;
|
class CObjectEntry;
|
||||||
class CBaseEntity;
|
class CBaseEntity;
|
||||||
|
class CMatrix3D;
|
||||||
|
|
||||||
// access to sole CObjectManager object
|
// access to sole CObjectManager object
|
||||||
#define g_ObjMan CObjectManager::GetSingleton()
|
#define g_ObjMan CObjectManager::GetSingleton()
|
||||||
|
|
||||||
|
// Slight hack, to allow ScEd to place either entities or objects
|
||||||
|
class CObjectThing
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~CObjectThing() {}
|
||||||
|
virtual void Create(CMatrix3D& transform, int playerID)=0;
|
||||||
|
virtual void SetTransform(CMatrix3D& transform)=0;
|
||||||
|
virtual CObjectEntry* GetObjectEntry()=0;
|
||||||
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// CObjectManager: manager class for all possible actor types
|
// CObjectManager: manager class for all possible actor types
|
||||||
class CObjectManager : public Singleton<CObjectManager>
|
class CObjectManager : public Singleton<CObjectManager>
|
||||||
@ -41,6 +52,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
CObjectThing* m_SelectedThing;
|
||||||
|
|
||||||
// constructor, destructor
|
// constructor, destructor
|
||||||
CObjectManager();
|
CObjectManager();
|
||||||
~CObjectManager();
|
~CObjectManager();
|
||||||
@ -55,7 +68,12 @@ public:
|
|||||||
|
|
||||||
CObjectBase* FindObjectBase(const char* objname);
|
CObjectBase* FindObjectBase(const char* objname);
|
||||||
|
|
||||||
CBaseEntity* m_SelectedEntity;
|
// Get all names, quite slowly. (Intended only for ScEd.)
|
||||||
|
void GetAllObjectNames(std::vector<CStr>& names);
|
||||||
|
|
||||||
|
//CBaseEntity* m_SelectedEntity;
|
||||||
|
void SetSelectedEntity(CBaseEntity* thing);
|
||||||
|
void SetSelectedObject(CObjectEntry* thing);
|
||||||
|
|
||||||
std::vector<SObjectType> m_ObjectTypes;
|
std::vector<SObjectType> m_ObjectTypes;
|
||||||
};
|
};
|
||||||
|
@ -245,6 +245,28 @@ CStr CStr::BeforeLast(const CStr& Str) const
|
|||||||
return substr(0, pos);
|
return substr(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve the substring following the first occurrence of Str
|
||||||
|
// (or the whole string if it doesn't contain Str)
|
||||||
|
CStr CStr::AfterFirst(const CStr& Str) const
|
||||||
|
{
|
||||||
|
long pos = Find(Str);
|
||||||
|
if (pos == -1)
|
||||||
|
return *this;
|
||||||
|
else
|
||||||
|
return substr(pos + Str.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the substring preceding the first occurrence of Str
|
||||||
|
// (or the whole string if it doesn't contain Str)
|
||||||
|
CStr CStr::BeforeFirst(const CStr& Str) const
|
||||||
|
{
|
||||||
|
long pos = Find(Str);
|
||||||
|
if (pos == -1)
|
||||||
|
return *this;
|
||||||
|
else
|
||||||
|
return substr(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove all occurrences of some character or substring
|
// Remove all occurrences of some character or substring
|
||||||
void CStr::Remove(const CStr& Str)
|
void CStr::Remove(const CStr& Str)
|
||||||
{
|
{
|
||||||
|
@ -184,6 +184,14 @@ public:
|
|||||||
// (or the whole string if it doesn't contain Str)
|
// (or the whole string if it doesn't contain Str)
|
||||||
CStr BeforeLast(const CStr& Str) const;
|
CStr BeforeLast(const CStr& Str) const;
|
||||||
|
|
||||||
|
// Retrieve the substring following the first occurrence of Str
|
||||||
|
// (or the whole string if it doesn't contain Str)
|
||||||
|
CStr AfterFirst(const CStr& Str) const;
|
||||||
|
|
||||||
|
// Retrieve the substring preceding the first occurrence of Str
|
||||||
|
// (or the whole string if it doesn't contain Str)
|
||||||
|
CStr BeforeFirst(const CStr& Str) const;
|
||||||
|
|
||||||
// Remove all occurrences of some character or substring
|
// Remove all occurrences of some character or substring
|
||||||
void Remove(const CStr& Str);
|
void Remove(const CStr& Str);
|
||||||
|
|
||||||
|
@ -10,9 +10,10 @@
|
|||||||
#include "BaseEntity.h"
|
#include "BaseEntity.h"
|
||||||
#include "BaseEntityCollection.h"
|
#include "BaseEntityCollection.h"
|
||||||
#include "EntityManager.h"
|
#include "EntityManager.h"
|
||||||
|
#include "ObjectManager.h"
|
||||||
|
|
||||||
CPaintObjectCommand::CPaintObjectCommand(CBaseEntity* object,const CMatrix3D& transform)
|
CPaintObjectCommand::CPaintObjectCommand(CObjectThing* object,const CMatrix3D& transform)
|
||||||
: m_BaseEntity(object), m_Transform(transform), m_Entity()
|
: m_Thing(object), m_Transform(transform), m_Entity()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,28 +24,12 @@ CPaintObjectCommand::~CPaintObjectCommand()
|
|||||||
|
|
||||||
void CPaintObjectCommand::Execute()
|
void CPaintObjectCommand::Execute()
|
||||||
{
|
{
|
||||||
CVector3D orient = m_Transform.GetIn();
|
m_Thing->Create(m_Transform, 1);
|
||||||
CVector3D position = m_Transform.GetTranslation();
|
|
||||||
m_Entity = g_EntityManager.create(m_BaseEntity, position, atan2(-orient.X, -orient.Z));
|
|
||||||
m_Entity->SetPlayer(g_Game->GetPlayer(1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPaintObjectCommand::UpdateTransform(CMatrix3D& transform)
|
void CPaintObjectCommand::UpdateTransform(CMatrix3D& transform)
|
||||||
{
|
{
|
||||||
CVector3D orient = transform.GetIn();
|
m_Thing->SetTransform(transform);
|
||||||
CVector3D position = transform.GetTranslation();
|
|
||||||
|
|
||||||
// This is quite yucky, but nothing else seems to actually work:
|
|
||||||
|
|
||||||
m_Entity->m_position =
|
|
||||||
m_Entity->m_position_previous =
|
|
||||||
m_Entity->m_graphics_position = position;
|
|
||||||
m_Entity->teleport();
|
|
||||||
|
|
||||||
m_Entity->m_orientation =
|
|
||||||
m_Entity->m_orientation_previous =
|
|
||||||
m_Entity->m_graphics_orientation = atan2(-orient.X, -orient.Z);
|
|
||||||
m_Entity->reorient();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -7,12 +7,13 @@
|
|||||||
|
|
||||||
class CUnit;
|
class CUnit;
|
||||||
class CBaseEntity;
|
class CBaseEntity;
|
||||||
|
class CObjectThing;
|
||||||
|
|
||||||
class CPaintObjectCommand : public CCommand
|
class CPaintObjectCommand : public CCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructor, destructor
|
// constructor, destructor
|
||||||
CPaintObjectCommand(CBaseEntity* entity, const CMatrix3D& transform);
|
CPaintObjectCommand(CObjectThing* entity, const CMatrix3D& transform);
|
||||||
~CPaintObjectCommand();
|
~CPaintObjectCommand();
|
||||||
|
|
||||||
// return the texture name of this command
|
// return the texture name of this command
|
||||||
@ -41,7 +42,7 @@ private:
|
|||||||
// unit to add to world
|
// unit to add to world
|
||||||
HEntity m_Entity;
|
HEntity m_Entity;
|
||||||
// entity to paint
|
// entity to paint
|
||||||
CBaseEntity* m_BaseEntity;
|
CObjectThing* m_Thing;
|
||||||
// model transformation
|
// model transformation
|
||||||
CMatrix3D m_Transform;
|
CMatrix3D m_Transform;
|
||||||
};
|
};
|
||||||
|
@ -45,7 +45,7 @@ void CPaintObjectTool::PaintSelection()
|
|||||||
m_Position=m_SelectionPoint;
|
m_Position=m_SelectionPoint;
|
||||||
m_LastTriggerTime=get_time();
|
m_LastTriggerTime=get_time();
|
||||||
|
|
||||||
CBaseEntity* obj=g_ObjMan.m_SelectedEntity;
|
CObjectThing* obj = g_ObjMan.m_SelectedThing;
|
||||||
if (obj) {
|
if (obj) {
|
||||||
// get up to date transform
|
// get up to date transform
|
||||||
BuildTransform();
|
BuildTransform();
|
||||||
@ -75,11 +75,11 @@ void CPaintObjectTool::OnDraw()
|
|||||||
// don't draw object if we're currently rotating it on the terrain
|
// don't draw object if we're currently rotating it on the terrain
|
||||||
if (m_PaintCmd) return;
|
if (m_PaintCmd) return;
|
||||||
|
|
||||||
CBaseEntity* ent=g_ObjMan.m_SelectedEntity;
|
CObjectThing* thing = g_ObjMan.m_SelectedThing;
|
||||||
if (!ent) return;
|
if (!thing) return;
|
||||||
|
|
||||||
// don't draw unless we have a valid object to apply
|
// don't draw unless we have a valid object to apply
|
||||||
CObjectEntry* obj = g_ObjMan.FindObject((CStr)ent->m_actorName);
|
CObjectEntry* obj = thing->GetObjectEntry();
|
||||||
if (!obj || !obj->m_Model) return;
|
if (!obj || !obj->m_Model) return;
|
||||||
|
|
||||||
// try to get object transform, in world space
|
// try to get object transform, in world space
|
||||||
|
@ -72,26 +72,18 @@ BOOL CUnitToolsDlgBar::OnInitDialog()
|
|||||||
// build combo box for object types
|
// build combo box for object types
|
||||||
CComboBox* objecttypes=(CComboBox*) GetDlgItem(IDC_COMBO_OBJECTTYPES);
|
CComboBox* objecttypes=(CComboBox*) GetDlgItem(IDC_COMBO_OBJECTTYPES);
|
||||||
|
|
||||||
const std::vector<CObjectManager::SObjectType>& types=g_ObjMan.m_ObjectTypes;
|
objecttypes->AddString("Entities");
|
||||||
for (uint i=0;i<types.size();i++) {
|
objecttypes->AddString("Actors");
|
||||||
objecttypes->AddString((const char*) types[i].m_Name);
|
|
||||||
}
|
|
||||||
if (types.size()>0) {
|
|
||||||
// select first type
|
|
||||||
objecttypes->SetCurSel(0);
|
objecttypes->SetCurSel(0);
|
||||||
|
|
||||||
// set initial list contents
|
|
||||||
// if (types.size()) {
|
|
||||||
// const std::vector<CObjectEntry*>& objects=types[0].m_Objects;
|
|
||||||
// for (uint i=0;i<objects.size();++i) {
|
|
||||||
// listctrl->InsertItem(i,(const char*) objects[i]->m_Name,i);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
std::vector<CStrW> names;
|
std::vector<CStrW> names;
|
||||||
g_EntityTemplateCollection.getTemplateNames(names);
|
g_EntityTemplateCollection.getBaseEntityNames(names);
|
||||||
for (size_t i = 0; i < names.size(); ++i)
|
for (size_t i = 0; i < names.size(); ++i)
|
||||||
listctrl->InsertItem(i, (CStr)names[i], i);
|
m_ObjectNames[0].push_back((CStr)names[i]);
|
||||||
}
|
|
||||||
|
g_ObjMan.GetAllObjectNames(m_ObjectNames[1]);
|
||||||
|
|
||||||
|
|
||||||
CButton* addunit=(CButton*) GetDlgItem(IDC_BUTTON_ADDUNIT);
|
CButton* addunit=(CButton*) GetDlgItem(IDC_BUTTON_ADDUNIT);
|
||||||
addunit->SetBitmap(::LoadBitmap(::GetModuleHandle(0),MAKEINTRESOURCE(IDB_BITMAP_ADDUNIT)));
|
addunit->SetBitmap(::LoadBitmap(::GetModuleHandle(0),MAKEINTRESOURCE(IDB_BITMAP_ADDUNIT)));
|
||||||
@ -101,6 +93,8 @@ BOOL CUnitToolsDlgBar::OnInitDialog()
|
|||||||
|
|
||||||
OnButtonSelect();
|
OnButtonSelect();
|
||||||
|
|
||||||
|
OnSelChangeObjectTypes();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +169,11 @@ void CUnitToolsDlgBar::OnClickListObjectBrowser(NMHDR* pNMHDR, LRESULT* pResult)
|
|||||||
// deselect current selection in list ctrl, if any
|
// deselect current selection in list ctrl, if any
|
||||||
POSITION pos=listctrl->GetFirstSelectedItemPosition();
|
POSITION pos=listctrl->GetFirstSelectedItemPosition();
|
||||||
if (pos) {
|
if (pos) {
|
||||||
// g_ObjMan.SetSelectedObject(g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects[(intptr_t)pos-1]);
|
CStrW name (CStr(listctrl->GetItemText((int)(intptr_t)pos-1, 0)));
|
||||||
g_ObjMan.m_SelectedEntity = g_EntityTemplateCollection.getTemplateByID((intptr_t)pos-1);
|
if (GetCurrentObjectType() == 0)
|
||||||
|
g_ObjMan.SetSelectedEntity(g_EntityTemplateCollection.getTemplate(name));
|
||||||
|
else
|
||||||
|
g_ObjMan.SetSelectedObject(g_ObjMan.FindObject((CStr)name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// shift to add mode
|
// shift to add mode
|
||||||
@ -193,18 +190,18 @@ int CUnitToolsDlgBar::GetCurrentObjectType()
|
|||||||
|
|
||||||
void CUnitToolsDlgBar::OnSelChangeObjectTypes()
|
void CUnitToolsDlgBar::OnSelChangeObjectTypes()
|
||||||
{
|
{
|
||||||
// // clear out the listctrl
|
// clear out the listctrl
|
||||||
// CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
|
CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
|
||||||
// listctrl->DeleteAllItems();
|
listctrl->DeleteAllItems();
|
||||||
//
|
|
||||||
// // add new items back to listbox
|
// add new items back to listbox
|
||||||
// std::vector<CObjectEntry*>& objects=g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects;
|
std::vector<CStr>& names=m_ObjectNames[GetCurrentObjectType()];
|
||||||
// for (uint i=0;i<objects.size();i++) {
|
for (uint i=0;i<names.size();i++) {
|
||||||
// // add to list ctrl
|
// add to list ctrl
|
||||||
// listctrl->InsertItem(i,(const char*) objects[i]->m_Name,i);
|
listctrl->InsertItem(i, names[i], i);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// g_ObjMan.SetSelectedObject(0);
|
g_ObjMan.SetSelectedObject(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUnitToolsDlgBar::OnButtonSelect()
|
void CUnitToolsDlgBar::OnButtonSelect()
|
||||||
|
@ -20,6 +20,8 @@ protected:
|
|||||||
BOOL OnInitDialog();
|
BOOL OnInitDialog();
|
||||||
int GetCurrentObjectType();
|
int GetCurrentObjectType();
|
||||||
|
|
||||||
|
std::vector<CStr> m_ObjectNames[2];
|
||||||
|
|
||||||
// Generated message map functions
|
// Generated message map functions
|
||||||
//{{AFX_MSG(CUnitToolsDlgBar)
|
//{{AFX_MSG(CUnitToolsDlgBar)
|
||||||
afx_msg void OnButtonAdd();
|
afx_msg void OnButtonAdd();
|
||||||
|
Loading…
Reference in New Issue
Block a user