Skip to content

Conversation

jerethk
Copy link
Contributor

@jerethk jerethk commented Apr 6, 2025

For this to work, I have created a "master list" of all objects that ever exist in a level: s_objectRefList
Objects are added to this list as they are created
When objects are deleted/freed, they are marked as removed but their position in the list is retained, so that IDs remain constant
(For now, I am not adding effects/explosions to the list, to keep down the size of the list. I have put the necessary code in place but commented it out. This is something that can be re-visited later if needed.)

Objects can be given a name and these names are serialised (along with the whole list)
The scripting API just has some basic functionality in it, that can be added to later

Create a "master list" of all objects that ever exist in a level, and serialize this list
Enable objects to be named
Add some basic scripting functionality
@jerethk jerethk marked this pull request as draft April 6, 2025 07:20
}

// Objects will be contained in the results array. Return value is the number of objects in the result.
int GS_Level::getAllObjectsByName(std::string name, CScriptArray& results)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array can already be queried for length in the script (arr.length) - so I don't think we need to also return the count.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep fair enough. Will change it.

ScriptObject GS_Level::getObjectByName(std::string name)
{
const char* cname = name.c_str();
if (!cname || strcmp(cname, "") == 0 || s_objectRefList.empty())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do name.empty() to see if the string is zero-length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for the tip :-)

if (obj && obj->sector)
{
RSector* sector = s_levelState.sectors;
for (u32 i = 0; i < s_levelState.sectorCount; i++, sector++)
Copy link
Owner

@luciusDXL luciusDXL Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just check sector->index and avoid the loop.
(You can still compare pointers if you want for extra security, but sector->index should never change) in the same level).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so sector->index is always going to match the ScriptSector m_id?
If that's the case, that makes it much easier.


// Other functions
ScriptObjFunc("void delete()", deleteObject);
ScriptObjFunc("void addLogic(string)", addLogicToObject);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to get the logic as well so you can see what you are fighting (stormtrooper, gran etc...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ifeldshteyn yes dealing with the logics will be in phase 2
:-)

ObjState_CustomLogics = 6,
ObjState_ConstOverrides = 7,
ObjState_CurVersion = ObjState_ConstOverrides,
ObjState_RefList = 8,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to load the old rObjdata if you load an older save?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the save was created before the new object reference list existed, then you won't be able to load it, no.
The list will simply be empty.

corpse->entityFlags |= ETFLAG_CORPSE;
sector_addObject(obj->sector, corpse);

obj_addToRefList(corpse, ObjRefType_Corpse); // scripting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not stick obj_addToRefList inside sector_addobject so you don't update multiple files?

Copy link
Contributor Author

@jerethk jerethk Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are different types of objects (corpse, spawned item, projectile, etc.) and once you are inside sector_addObject you have no idea what type of object it is.
See the ObjectRefType enum

The idea is that eventually there may be functionality to let you get all objects of a certain category so you can do something with them.
For example make all projectiles stop in mid-air. Make all corpses levitate/vanish. Or whatever.

@jerethk jerethk marked this pull request as ready for review April 10, 2025 10:05
@jerethk jerethk requested a review from luciusDXL April 10, 2025 10:05
}
else if (logicId >= KW_BATTERY && logicId <= KW_AUTOGUN)
{
// TODO
Copy link
Owner

@luciusDXL luciusDXL Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to write out a message/warning to the console that the requested logic isn't supported or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intention is to get it done in the near future :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I've done it now :-)
Just a 1 line commit

jerethk added 2 commits April 18, 2025 22:56
# Conflicts:
#	TheForceEngine/TFE_Jedi/Level/robjData.h
@luciusDXL luciusDXL merged commit 3d68d2e into luciusDXL:master Aug 29, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants