Jump to content
  • Advertisement
Sign in to follow this  
noodleBowl

User defined functions?

This topic is 1010 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if there is a way to have user defined functions?
 
Here is my situation, I'm trying my hand at multi-platform code.

I have a source file that has multiple main functions meant for their specific platform. When I compile a specific platform, the main function for that platform will be the one available and act as the programs entry point. So for example:
 
Desktop compile would have and use the typical main:

void main()
{
   //Program entry point
}

 
Where compiling for Android would use and have this main function:

ANativeActivity_createFunc AndroidStart;
void AndroidStart (ANativeActivity *activity, void *savedState, size_t savedStateSize)
{
   //Program entry point
}

Now I'm looking to have some user defined functions for Update and Render. Where these are automatically called by the internals of my code, but are what the user needs to have. Something like:

 

 
//In the internals of on my android application
void MainThreadRun()
{
     while(running)
     {
            HandlePollData();
 
            //User functions that the user made
            UserDefinedUpdate();
            UserDefinedRender();
     }
}
 

 

I was hoping I could do something like an extern method, but seeing that I want to package my code up as a SO / DLL library. Making methods like those and declaring them extern cause linker errors. Which makes sense cause they would not be declared in my code.

 

So what can I do? What are some better options?

Share this post


Link to post
Share on other sites
Advertisement

The easiest and most intuitive way to allow users control over updating and rendering is to use polymorphism.
General Game/Engine Structure
Obviously this works over DLL’s as your DLL factory just needs to spit out the appropriate instance type.


L. Spiro

 

100% honest, this is Ironic

 

I am porting my engine over from Java and originally in my Java code I had a Engine / Application class. Where the user extended from this class and used override methods on things like Update, Render, etc. But when I came over to C++ I felt that this was "too" Java and went a completely different direction

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!