1
0
forked from 0ad/0ad

ScEd: allowed creation of non-entity objects, pending total entitisation

This was SVN commit r2085.
This commit is contained in:
Ykkrosh 2005-03-30 05:43:22 +00:00
parent b07d9954e0
commit 8b12c84df7
9 changed files with 181 additions and 62 deletions

View File

@ -8,6 +8,13 @@
#include "VFSUtil.h"
#include "ObjectBase.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"
@ -21,7 +28,7 @@ bool operator< (const CObjectManager::ObjectKey& a, const CObjectManager::Object
return a.ActorVariation < b.ActorVariation;
}
CObjectManager::CObjectManager() : m_SelectedEntity(NULL)
CObjectManager::CObjectManager() : m_SelectedThing(NULL)
{
m_ObjectTypes.reserve(32);
}
@ -152,3 +159,82 @@ void CObjectManager::LoadObjects()
{
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);
}

View File

@ -10,10 +10,21 @@
class CObjectBase;
class CObjectEntry;
class CBaseEntity;
class CMatrix3D;
// access to sole CObjectManager object
#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
class CObjectManager : public Singleton<CObjectManager>
@ -41,6 +52,8 @@ public:
};
public:
CObjectThing* m_SelectedThing;
// constructor, destructor
CObjectManager();
~CObjectManager();
@ -55,7 +68,12 @@ public:
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;
};

View File

@ -245,6 +245,28 @@ CStr CStr::BeforeLast(const CStr& Str) const
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
void CStr::Remove(const CStr& Str)
{

View File

@ -184,6 +184,14 @@ public:
// (or the whole string if it doesn't contain Str)
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
void Remove(const CStr& Str);

View File

@ -10,9 +10,10 @@
#include "BaseEntity.h"
#include "BaseEntityCollection.h"
#include "EntityManager.h"
#include "ObjectManager.h"
CPaintObjectCommand::CPaintObjectCommand(CBaseEntity* object,const CMatrix3D& transform)
: m_BaseEntity(object), m_Transform(transform), m_Entity()
CPaintObjectCommand::CPaintObjectCommand(CObjectThing* object,const CMatrix3D& transform)
: m_Thing(object), m_Transform(transform), m_Entity()
{
}
@ -23,28 +24,12 @@ CPaintObjectCommand::~CPaintObjectCommand()
void CPaintObjectCommand::Execute()
{
CVector3D orient = m_Transform.GetIn();
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));
m_Thing->Create(m_Transform, 1);
}
void CPaintObjectCommand::UpdateTransform(CMatrix3D& transform)
{
CVector3D orient = transform.GetIn();
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();
m_Thing->SetTransform(transform);
}
//////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -7,12 +7,13 @@
class CUnit;
class CBaseEntity;
class CObjectThing;
class CPaintObjectCommand : public CCommand
{
public:
// constructor, destructor
CPaintObjectCommand(CBaseEntity* entity, const CMatrix3D& transform);
CPaintObjectCommand(CObjectThing* entity, const CMatrix3D& transform);
~CPaintObjectCommand();
// return the texture name of this command
@ -41,7 +42,7 @@ private:
// unit to add to world
HEntity m_Entity;
// entity to paint
CBaseEntity* m_BaseEntity;
CObjectThing* m_Thing;
// model transformation
CMatrix3D m_Transform;
};

View File

@ -45,7 +45,7 @@ void CPaintObjectTool::PaintSelection()
m_Position=m_SelectionPoint;
m_LastTriggerTime=get_time();
CBaseEntity* obj=g_ObjMan.m_SelectedEntity;
CObjectThing* obj = g_ObjMan.m_SelectedThing;
if (obj) {
// get up to date transform
BuildTransform();
@ -75,11 +75,11 @@ void CPaintObjectTool::OnDraw()
// don't draw object if we're currently rotating it on the terrain
if (m_PaintCmd) return;
CBaseEntity* ent=g_ObjMan.m_SelectedEntity;
if (!ent) return;
CObjectThing* thing = g_ObjMan.m_SelectedThing;
if (!thing) return;
// 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;
// try to get object transform, in world space

View File

@ -71,27 +71,19 @@ BOOL CUnitToolsDlgBar::OnInitDialog()
// build combo box for object types
CComboBox* objecttypes=(CComboBox*) GetDlgItem(IDC_COMBO_OBJECTTYPES);
const std::vector<CObjectManager::SObjectType>& types=g_ObjMan.m_ObjectTypes;
for (uint i=0;i<types.size();i++) {
objecttypes->AddString((const char*) types[i].m_Name);
}
if (types.size()>0) {
// select first type
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;
g_EntityTemplateCollection.getTemplateNames(names);
for (size_t i = 0; i < names.size(); ++i)
listctrl->InsertItem(i, (CStr)names[i], i);
}
objecttypes->AddString("Entities");
objecttypes->AddString("Actors");
objecttypes->SetCurSel(0);
std::vector<CStrW> names;
g_EntityTemplateCollection.getBaseEntityNames(names);
for (size_t i = 0; i < names.size(); ++i)
m_ObjectNames[0].push_back((CStr)names[i]);
g_ObjMan.GetAllObjectNames(m_ObjectNames[1]);
CButton* addunit=(CButton*) GetDlgItem(IDC_BUTTON_ADDUNIT);
addunit->SetBitmap(::LoadBitmap(::GetModuleHandle(0),MAKEINTRESOURCE(IDB_BITMAP_ADDUNIT)));
@ -101,6 +93,8 @@ BOOL CUnitToolsDlgBar::OnInitDialog()
OnButtonSelect();
OnSelChangeObjectTypes();
return TRUE;
}
@ -175,8 +169,11 @@ void CUnitToolsDlgBar::OnClickListObjectBrowser(NMHDR* pNMHDR, LRESULT* pResult)
// deselect current selection in list ctrl, if any
POSITION pos=listctrl->GetFirstSelectedItemPosition();
if (pos) {
// g_ObjMan.SetSelectedObject(g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects[(intptr_t)pos-1]);
g_ObjMan.m_SelectedEntity = g_EntityTemplateCollection.getTemplateByID((intptr_t)pos-1);
CStrW name (CStr(listctrl->GetItemText((int)(intptr_t)pos-1, 0)));
if (GetCurrentObjectType() == 0)
g_ObjMan.SetSelectedEntity(g_EntityTemplateCollection.getTemplate(name));
else
g_ObjMan.SetSelectedObject(g_ObjMan.FindObject((CStr)name));
}
// shift to add mode
@ -193,18 +190,18 @@ int CUnitToolsDlgBar::GetCurrentObjectType()
void CUnitToolsDlgBar::OnSelChangeObjectTypes()
{
// // clear out the listctrl
// CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
// listctrl->DeleteAllItems();
//
// // add new items back to listbox
// std::vector<CObjectEntry*>& objects=g_ObjMan.m_ObjectTypes[GetCurrentObjectType()].m_Objects;
// for (uint i=0;i<objects.size();i++) {
// // add to list ctrl
// listctrl->InsertItem(i,(const char*) objects[i]->m_Name,i);
// }
//
// g_ObjMan.SetSelectedObject(0);
// clear out the listctrl
CListCtrl* listctrl=(CListCtrl*) GetDlgItem(IDC_LIST_OBJECTBROWSER);
listctrl->DeleteAllItems();
// add new items back to listbox
std::vector<CStr>& names=m_ObjectNames[GetCurrentObjectType()];
for (uint i=0;i<names.size();i++) {
// add to list ctrl
listctrl->InsertItem(i, names[i], i);
}
g_ObjMan.SetSelectedObject(0);
}
void CUnitToolsDlgBar::OnButtonSelect()

View File

@ -20,6 +20,8 @@ protected:
BOOL OnInitDialog();
int GetCurrentObjectType();
std::vector<CStr> m_ObjectNames[2];
// Generated message map functions
//{{AFX_MSG(CUnitToolsDlgBar)
afx_msg void OnButtonAdd();