Jump to content
  • Advertisement
Sign in to follow this  
DevilWithin

Inter-module class access

This topic is 1670 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

Hello,

 

I am currently trying to solve an issue and I'd like some direction on the best way to handle it.

 

In essence, my game has a few states (intro, loading, menu, game, pause, etc), each state is a unique class defined in a unique file, and they all inherit from a common interface GameState.

 

Right now, I am compiling each class into its own module, which creates the problem that I can't access classes from other modules and I need to do things like that, for example, the loading script would get the handle to the game script object, and would change some values in that state object for game initialization. 

 

How should I handle this? Move all classes to a single module so they can access each other mutually? Should I use a messaging system instead? Is there any other recommended way?

 

Also, in case of maintaining a single module for all my classes, besides avoiding name collisions, should I have any other concerns? Is there a problem if I add later other classes into this module, whenever there is the need?

 

Thanks

Share this post


Link to post
Share on other sites
Advertisement

There is a class in AngelScript addons, called CScriptBuilder. It allows you to create modules from several files (or memory). Besides that, it allows you to use C-style includes in your scripts.

Share this post


Link to post
Share on other sites

There are benefits to both ways. By building everything into a single module you will have an easier task of inter-communication between objects, but by keeping the objects in different modules you will be able to treat each individually (for example, exposing different engine interfaces, load on demand, hot-loading, serializing, etc).

 

 

To solve inter-communication between classes in different modules, you can use shared types and imported functions, or you can build a messaging system like you said.

Share this post


Link to post
Share on other sites

Thanks Andreas :) 

 

Those features you mention do sound promising, I think I am convinced, each state will sit in a independent module.

 

First, the dynamic nature of my state system would be impractical. I'd have to specify all game states source at init time, or it would be a total mess with classes referencing other classes that aren't compiled yet, generating a ugly dependency.

 

Also, I will definitely create a Messaging system as a clear interface to communicate between states. This is really the best way as I can create premade states for multiple things and re-use them quite easily. For example, I create a pause state and document it so everyone knows it is expecting a "UI_Source_File" at initialization. Then, I can re-use the same pause game code for many games, only changing its looks by those properties. Sounds like the cleanest approach to me.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!