Author Topic: does such a thing exsist? (scripting question)  (Read 1903 times)

0 Members and 1 Guest are viewing this topic.

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
does such a thing exsist? (scripting question)
is there currently a ship specific array with the sole purpose of being a scratch pad area for scripts? just simply a place where script defined variables can be made and used by scripts for scripts?
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: does such a thing exsist? (scripting question)
Unfortunately, no. It would be really great though; having to write your own metadata system isn't that cool.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: does such a thing exsist? (scripting question)
this is kinda why i wrote my own meta system, which in turn required the object:getSignature() and mn.getObjectFromSignature() functions (which i added some time ago). while ship handles only last a frame a signature is good for the duration of the game. it works with anything that is an object derivative (ships, weapons, asteroids etc). so you can just make a table and use the signature as an index. and place all data for that object in that table. then its just a matter of cleaning up dead entries and initing defaults for new objects. both my cockpit script and the atmospheric flight script have variations on such a system. this is useful for instance data, for static class information i just use my table parser.

having this functionality built into the game would actually be a pretty awesome feature. every class of object and every instance of an object would need to each have their own data store. having every object have a persistent lua table associated with it where you can put information about that object would save time. to cover class data id suggest adding a means to enter custom data into ship and weapons tables. simply having a text block which can be accessed through the relevant object class handle would be awesome, data here can be parsed in script. take it a step further and have pre-parsed variables in common lua types and lua supported objects (like vectors) would even be cooler. but its not like you cant write the same thing in lua with only a small amount of effort (my parser for example is a stand alone script for the most part, so feel free to use it).
« Last Edit: September 20, 2011, 01:22:29 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: does such a thing exsist? (scripting question)
and it would make it super easy to incorporate scripted values into places where constants are the only easy way to go.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: does such a thing exsist? (scripting question)
i suggested these features early on in the course of the scripting system. though none of the were implemented. somewhere i started using dirty hacks to pair an object with a place in a meta table, such as using an objects name and a couple other pieces of info to build a hash of sorts and then be able to pull up the right object. this had problems of course, you had to handle each kind of object differently. weapons were very hard to keep track of for example and liked to get their meta crossed. on top of that the system was slow, it took a lot of time in loops to accomplish, so i went into the engine and exposed the signature so you have a unique identifier for every object in the game, and so far its worked great and doesn't use much overhead within the scripting environment.
« Last Edit: September 20, 2011, 01:31:03 am by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: does such a thing exsist? (scripting question)
problem with that is the engine is unaware of it, so if you want to tie a piece of metadata to something else, you can't, at least not easily/cleanly.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: does such a thing exsist? (scripting question)
to what else would you want to attach meta?

for reference this is the meta system from the cockpit demo, which (aside from player cockpit simulation) offer a number of new features for ships and weapons, like animated gatling turrets and missiles that shout at you. the system is self maintaining. if you try to get meta for a new object, it is created, if you try to get an object from meta that no longer exists, that meta is deleted. the cleanup cycle hunts down dead objects and deletes those every few frames. its a pretty cool little system that works.

Code: [Select]
-----------------------------------
------------meta system------------
-----------------------------------
--[[
to use this meta system just call init_meta at the start (and end) of a mission, then call get_meta_from_object on any object you want to
assign meta to. this calls the default handler for that object type and adds the default values to the object's meta.
it returns the table containing that object's meta, which may then be read or modified. if you want to get
an object handle from that meta you can also call get_object_from_meta with an objects meta array. the meta system automatically
cleans up dead meta by calling maybe_clean_meta(interval) in the frame/simulation hooks. type specific defaults may be set in
create_default_meta() after the "--breed handlers may be added after this point" line. they may be handled there or passed to other
functions. its a good idea not to handle every kind of object, only ones you require meta for, and even then you may want to only
certain objects of each type, such as all ships with a certain name. anything not added will not have any meta entry and saves
memory.
]]--
--call this at the beginning of a mission (and at the end too)
function init_meta()
--the really large metatable from hell
meta = {}
--reset the cleanup clock
clean_meta_time = 10
end
--look up meta with any object handle, if not found tries to create it, on failure returns nil otherwise meta array
function get_meta_from_object(obj)
--ba.print("Getting meta from object\n")
if obj:isValid() then
local s = obj:getSignature()
if not meta[s] then --no meta found, try to create it
meta[s] = create_default_meta(obj)
end
--maybe return it
if meta[s] then
return meta[s]
end
end
return nil
end
--look up object based on meta array, if the object is invalid then meta is deleted
--returns object handle on success, returns false on deletion, or returns nil on failure
function get_object_from_meta(met)
--ba.print("Getting object from meta\n")
if met and met.sig then
local obj = mn.getObjectFromSignature(met.sig)
if obj:isValid() then
return obj
else --object is no longer valid, no need to keep the meta in the system
meta[met.sig] = nil
return false
end
end
return nil
end
--delete dead meta, returns number remaining and number deleted (or 0,0 if nothing happens)
function clean_meta()
ba.print("Cleaning meta\n")
local deleted, scanned = 0,0
for k in pairs(meta) do
scanned = scanned + 1
local ismeta = get_object_from_meta(meta[k])
if not ismeta and ismeta == false then
deleted = deleted + 1
end
end
return scanned-deleted, deleted
end
--do meta cleanups periodically, call every frame, but will only clean if interval has passed
--dont forget to reset clean_meta_time at mission start
function maybe_clean_meta(interval)
if not interval then interval = 10 end
if mn.getMissionTime() > clean_meta_time then
local r,d = clean_meta()
ba.print("Metadata cleanup cycle, Entries remaining: "..r..", Deleted: "..d.."\n")
--set next clean time
clean_meta_time = clean_meta_time + interval
end
end
--generic meta create, create meta lookup info, and calls the proper defaults function
function create_default_meta(obj)
local s = obj:getSignature()
ba.print("Creating default meta for object with sig: "..tostring(s).."\n")
meta[s] = {}
meta[s].sig = s
meta[s].breed = obj:getBreedName()
--breed handlers may be added after this point
if meta[s].breed == "Ship" then
if create_default_ship_meta(meta[s], obj) then
return meta[s]
end
elseif meta[s].breed == "Weapon" then
if create_default_wep_meta(meta[s], obj) then
return meta[s]
end
end
--breed not handled, clear the meta and return the nil
ba.print("No defaults handled for this object\n")
return meta[s]
end
--type specific default functions, returns true if defaults loaded, false otherwise
--creates weapon meta
function create_default_wep_meta(met, wep)
ba.print("Creating default weapon meta for: "..wep.Class.Name.."\n")
local winfo = drones_tbl.drone_info[wep.Class.Name]
--only apply meta to weapons that have special drone features
if winfo then
--all weapon defaults
--set missile orientation to match ship's
wep.Orientation = wep.Parent.Orientation
--does it belong to player
met.is_player = (wep.Parent == hv.Player)
--drone infofotable link
met.info = winfo
--control information
met.speed_p = 0 --desired turn rates (-1..1)
met.speed_b = 0
met.speed_h = 0
--the place where the missile wants to be
met.lpos = wep.Position + wep.Orientation:unrotateVector(ba.createVector(0,0,wep.Class.Range))
--ucav only fields
if winfo.type == "ucav" then
--drone weapon class
met.weapon = tb.WeaponClasses[winfo.weapon]
--ammo remaining
met.ammo = winfo.ammo
--last firing
met.lastfire = 0
--current fire point
met.curpoint = 1
--control info
met.speed_t = 1 --forward speed (0..1)
--fire weapon
met.trigger = false
elseif winfo.type == "multitarget" then
--name of target ship
met.tname = ""
--stuf would normally go here, if it existed
elseif winfo.type == "lgb" then
--last laser position found
met.last_laser_fix = ba.createVector()
--last time laser was updated
met.last_laser_fix_time = -1
end
return true
end
--no data stored
return false
end
--creates ship and subsysem meta
function create_default_ship_meta(met, shp)
ba.print("Creating default ship meta for: "..shp.Class.Name.."\n")
local class = cockpits_tbl.shipinfo[shp.Class.Name]
if class then
ba.print("Can has special features?\n")
if class.targeting_laser then
ba.print("Can has targeting laser!\n")
--last reported dot position
met.laser_spot_pos = ba.createVector()
--last time stamp at which laser was good
met.laser_spot_time = -1
end
if class.multi_targeting then
ba.print("Can has multi targeting!\n")
met.lock_list = {}
met.lock_list_names = {}
end
if class.turrets then
ba.print("Can has advanced turrets!\n")
--turrets
met.turrets = {}
for i = 1, #class.turrets do
if class.turrets[i] and class.turrets[i].gatling_subsystem and shp[class.turrets[i].gatling_subsystem]:isValid() then
--all ship defaults
met.turrets[class.turrets[i].index_name] = {}
--gun physics
met.turrets[class.turrets[i].index_name].gat_cur_ang = 0
met.turrets[class.turrets[i].index_name].gat_old_ang = 0
met.turrets[class.turrets[i].index_name].gat_cur_rps = 0
--heat level
met.turrets[class.turrets[i].index_name].gun_heat = 0
--ai burst timestamps
met.turrets[class.turrets[i].index_name].burst_start = 0
met.turrets[class.turrets[i].index_name].next_burst = 0
--toggle between ai and player operation
met.turrets[class.turrets[i].index_name].use_ai = true
--player fire command
met.turrets[class.turrets[i].index_name].fire = false
--last used angles (for smooth transition between ai and player operation)
met.turrets[class.turrets[i].index_name].last_base_angle = 0
met.turrets[class.turrets[i].index_name].last_barrel_angle = 0
end
end
end
return true
end
return false
end

last 2 functions are changed to suit the needs of your script, in this case it loads a bunch of data from tables parsed by my table parser.  while im only handling ships and weapons here, i could also apply meta to any other object class derivative, as they are needed. if you tried to get meta on object like an asteroid it would still create a blank meta table for that object (with its breed and signature as elements). if you wanted to do anything with that meta, well you might want to create a default handler for that.
« Last Edit: September 20, 2011, 03:52:00 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: does such a thing exsist? (scripting question)
well, you could make a new sub-object attribute that took the name of some metadata and then it used that as it's rotation matrix. a million other things like that, it would enable redirecting script actions to in game stuff super easy.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: does such a thing exsist? (scripting question)
the meta system i have can do that. it needs to keep track of the orientation of the gatling turrets so that it can accelerate/decelerate them correctly. i must point out that i wouldn't be against an in-engine meta system. we would need hooks for the creation (and perhaps destruction) of every derivative of object. some kind of On Object Create hook to init this built in meta with user variables (and perhaps an On Object Destroyed hook to un-init things, like textures). i assume it would work by directly associating a lua table (or perhaps some class in c) with an object that lasts for the duration of that object. this covers instance meta.

class meta (which i dont treat as meta as much as data parsed from various files) would be be static read-only data parsed from their associated tables, such as using a structure like this (in, for example, a ships.tbl entry):
Code: [Select]
$scripting meta:
 +string variable: variableName
 +string value:     "i am a string"
 +number variable: anotherVariableName
 +number value:   3.14159
 +boolean variable: yesno
 +boolean variable: true
 +vector variable: somevector
 +vector value:  1,2,3
and then on the scripting you see:
Code: [Select]
ship.Class.scriptingVars[variableName] == variablevalue
id be concerned that a system like that would only be implemented in a couple object class derivatives. when i implemented the getSignature() and getObjectFromSignature(), they initially were only implemented at the weapon level, because at the time i had a means to do the same for ships with script. but i quickly realized that it would benefit everyone a lot more if it worked at the object level and changed it at the last minute. so if this were implemented it would need to be a pretty broad reaching thing.
« Last Edit: September 20, 2011, 07:21:22 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

  

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: does such a thing exsist? (scripting question)
well, then maybe this isn't needed after all. there just needs to be hooks into what ever variable you want to modify, that seems sort of obvious...
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together