Override Blitz Native Command and Then Revert

Blitz3D Forums/Blitz3D Programming/Override Blitz Native Command and Then Revert

Rob the Great(Posted 2013) [#1]
Hey all,

I'm scared to even ask this, because I think I already know the answer.

I've got a large game going, and I wish to modify the FreeEntity command with a custom function so I don't have to spend hours using the Find...Replace function. It just needs to check if the entity handle is a sprite and then release the sprite using other custom functions before releasing the entity itself.

Here's the problem:
Function FreeEntity(entity)


      If EntityClass$(entity) = "Sprite"
            ;Delete the sprite types associated with this entity
      EndIf

      FreeEntity entity  ;This will lead to infinite recursion because it goes to my FreeEntity() function, not Blitz's.


End Function


Is there any way to revert back to a Blitz native command after overriding it? I doubt there is, but it would be awesome if such a thing existed.


Rob the Great(Posted 2013) [#2]
Never mind. As I feared, this post answers my question.

http://blitzbasic.com/Community/posts.php?topic=98946#1159402


Yasha(Posted 2013) [#3]
This is probably a stupid question to ask, but why would using Find/Replace be a problem? If you're working in IDEal, there's a "Replace all in project" option that I would have thought can handle this in a matter of seconds.

If your project isn't in IDEal, or is too big to fit entirely in IDEal, you could use sed to rename a function across multiple files: http://www.microhowto.info/howto/globally_rename_an_identifier_throughout_a_set_of_source_files.html

You can download GNU sed for Windows here: http://gnuwin32.sourceforge.net/packages/sed.htm

(You'll actually need to combine sed with find - which is also available as a GnuWin32 package - in order to recursively descend through a folder hierarchy and rename functions as you go: http://blog.gabrielsaldana.org/search-and-replace-recursively-in-multiple-files/ )


Rob the Great(Posted 2013) [#4]
Actually, I do use IDEal. I guess that my concern was more about forgetting to use FreeEntityCustom() with future code, so I was hoping to be able to just replace FreeEntity and not have to worry about it.

I actually did use the Replace All to replace all current FreeEntity commands with FreeEntityCustom. Yes, I might forget about this change when I am coding later on, but if that happens, I'm sure I will remember when I get a MAV.

The reason I need to check for sprites when freeing an entity is because I'm using artificial sprites that are actually quad meshes. I found a technique in the code archives that's able to override all of the sprite commands, making it pretty easy to implement. The catch is that there isn't a FreeSprite command built in to Blitz, so there's no easy way to release the sprite from the type list using this override method.

The more that I think about it, the more that I realize that what I was trying to do was useless anyway due to the fact that the artificial sprites are not sprites, but meshes. This means that EntityClass$() would have no way to distinguish between an artificial sprite and a regular mesh.