indexing description: "[ This is a sketch using a first implementation together with EM3D_IDENTIFIED. Two ways are possible: use EM3D_IDENTIFIED.object_by_name or manage own DS_HASH_TABLE and map strings onto object_id of identified. This is however not intendet to be used for resources. ]" date: "$Date$" revision: "$Revision$" class EM3D_OBJECT_MANAGER[G -> EM3D_MOVABLE create make end] inherit EM3D_IDENTIFIED[ G ] export {NONE} all redefine type, default_name end create make, make_with_creation_constraint feature -- Initialisation make (a_scene_manager: EM3D_SCENE_MANAGER) is -- Initialise require a_scene_manager_not_void: a_scene_manager /= Void do has_no_creation_constraint := True scene_manager := a_scene_manager create objects.make -- TODO: Replace this by once("OBJECT") as soon as it's supported -- Initialize the identified object create identified_object.make( void ) ensure scene_manager_set: scene_manager = a_scene_manager end make_with_creation_constraint (a_scene_manager: EM3D_SCENE_MANAGER; a_predicate: FUNCTION[ANY,TUPLE[],BOOLEAN]) is -- Initialise do make( a_scene_manager ) has_no_creation_constraint := False creation_predicate := a_predicate ensure scene_manager_set: scene_manager = a_scene_manager creation_predicate_set: creation_predicate = a_predicate end feature {EM3D_IDENTIFIED} identified_object: G default_name: STRING is do result := identified_object.default_name end type: INTEGER is -- Specify the identified type do result := identified_object.type end feature -- Access create_new_unnamed: G is -- Crate a new instance require creation_possible: has_no_creation_constraint or is_creation_of_a_new_instance_possible local i: INTEGER do from i:=0 until object_by_name( default_name+i.out )=void loop i := i + 1 end result := create_new( default_name+i.out ) end create_new (a_name: STRING): G is -- Crate a new instance require is_valid_name: is_valid_name (a_name) creation_possible: has_no_creation_constraint or is_creation_of_a_new_instance_possible local -- ISE Eiffel 6.0.6.7775 Bug local_scene_manager: EM3D_SCENE_MANAGER do local_scene_manager := scene_manager create Result.make( local_scene_manager ) Result.set_name (a_name) objects.put_last( Result.object_id ) end item_by_name (a_name: STRING): G is -- Return a reference for item name `a_name'. require has_item: has_item_by_name (a_name) do Result ?= object_by_name (a_name) end item_by_id (an_id: INTEGER): G is -- Return a reference for item name `a_name'. require has_item: has_item_by_id (an_id) do Result ?= id_object (an_id) end feature {EM3D_SCENE_MANAGER}-- Access scene_manager: EM3D_SCENE_MANAGER -- Scene manager. objects: DS_BILINKED_LIST[ INTEGER ] -- Objects saved in the manager feature -- Status report has_item_by_name (a_name: STRING): BOOLEAN is -- Do we have an item named `a_name'? do Result := object_by_name (a_name) /= void end has_item_by_id (an_id: INTEGER): BOOLEAN is -- Do we have an item with id `an_id'? do Result := id_object (an_id) /= void end has_no_creation_constraint: BOOLEAN -- Do we have any creation constraints to check? is_creation_of_a_new_instance_possible: BOOLEAN is -- Is creation of a new instance possible? -- This is not always possible, because of limited hardware capabilities. do -- We could use here an agent which needs to be specified by the scene manager for each object type we have. -- For example lights. Result := True if creation_predicate /= Void then Result := creation_predicate.item ([]) end end is_valid_name (a_name: STRING): BOOLEAN is -- Is `a_name' a valid name. do Result := not has_item_by_name (a_name) end feature -- Status setting do_all( action: PROCEDURE[ ANY , TUPLE[ G ] ] ) is -- call 'action' for each element registres in this EM3D_OBJECT_MANAGER local cursor: DS_BILINKED_LIST_CURSOR[ INTEGER ] do cursor := objects.new_cursor from cursor.start until cursor.after loop if has_item_by_id(cursor.item) then action.call( [item_by_id( cursor.item )] ) cursor.forth else cursor.remove end end end feature -- Cursor movement feature -- Element change feature -- Removal remove_all is -- Removes all items do check false end -- Here we should find all references to items and remove them from the scene graph. -- Maybe we can also forget about this feature... end feature -- Resizing feature -- Transformation feature -- Conversion feature -- Duplication feature -- Miscellaneous feature -- Basic operations feature -- Obsolete feature -- Inapplicable feature {NONE} -- Implementation creation_predicate: FUNCTION[ANY,TUPLE[],BOOLEAN] -- States wheter creation of new instances is possible or not. invariant invariant_clause: True -- Your invariant here end