-
Notifications
You must be signed in to change notification settings - Fork 77
Introduce ScriptObject class for object scripting #520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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
} | ||
|
||
// 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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++) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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...)
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
} | ||
else if (logicId >= KW_BATTERY && logicId <= KW_AUTOGUN) | ||
{ | ||
// TODO |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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
# Conflicts: # TheForceEngine/TFE_Jedi/Level/robjData.h
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