Thread: Problems with modules

  1. #1
    Linker.exe64
    Join Date
    Mar 2005
    Location
    Croatia,Pozega
    Posts
    37

    Problems with modules

    // http://www.cprogramming.com/tutorial/gamedesign.html

    I have read article about modules (game design) && I'm having some problems with implementation...

    When I try to compile my code, it works. I run the program && get unhandled exception error... Program exits and places my pointer on the following line :
    Code:
    if ( (GameMod = GameMod->execute_module()) != OldMod )
    Can someone help me with this? Code is too big to put here. If anyone has some time, I can send complete source code and VS.NET 2003 project file in .zip archive.


    And... can you give me advice where should I use modules. Do I need to make module for everything or...?

    For example, I have class Unit, class Vehicle... Should I also make modules for them?

    Still confused with these modules...

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You should read through the discussion thread, jverkoey made some posts that might clear up your confusion a bit.

    And I can't really say what your problem is without seeing some code...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Linker.exe64
    Join Date
    Mar 2005
    Location
    Croatia,Pozega
    Posts
    37
    Here is the source : http://www.myfilestash.com/userfiles...se_00000_1.zip

    [NOTE] :
    Some files have been excluded from the project.

    I think that problem is in those 'extern Module* x...' ,
    tried many things but can't get thing to work.
    Last edited by 81N4RY_DR460N; 07-29-2005 at 01:05 PM.

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I think you should put the extern's in module.h, declare them without extern in the corresponding .cpp file. ie:
    Code:
    //module.h
    class Module
    {
    //...
    }
    
    extern Module* GameMod;
    //...
    Code:
    //GameModule.cpp
    Module* GameMod;
    
    //...
    Then you need to allocate those with new (probably in some initialization function (in GameLoop.cpp i guess):
    Code:
    Module* this_file_gamemod = GameMod; //don't confuse the two
    
    void Startup()
    {
    GameMod = new GameModule();
    this_file_gamemod = GameMod;
    }
    
    void GameLoop()
    {
    
    Module* oldmod = this_file_gamemod;
    //...
    
    }
    
    void ShutDown()
    {
      delete GameMod;
    }
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Linker.exe64
    Join Date
    Mar 2005
    Location
    Croatia,Pozega
    Posts
    37
    Module && GameModule are abstract classes, so I can't use new on them.

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Well its not going to work the way you have it here:
    Code:
    Module*	GameMod = NULL;
    	Module*	LastMod = NULL;
    
    	//-----------------------------------------------------------------
    	//	GameLoop()
    	//-----------------------------------------------------------------
    	void GameLoop()
    	{
    
    		Module* OldMod = GameMod;
    
    		if ((GameMod = GameMod->execute_module()) != LastMod)
    		{
    			LastMod = OldMod;
    
    		}
    	}
    If GameMod is null then you can't call its member functions...Unless I'm missing something?

    I don't think GameModule should be an abstract class, in any case...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Linker.exe64
    Join Date
    Mar 2005
    Location
    Croatia,Pozega
    Posts
    37
    I'm still new to abstract classes. How can I make class not to be abstract ?
    Make pure virtual ( =0) functions virtual ?

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    A class is abstract if it has a pure virtual function IIRC (that is, a virtual function with =0 at the end of the declaration)

    So you shouldn't have any virtuals in GameModule, just normal function declarations and definitions
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    Linker.exe64
    Join Date
    Mar 2005
    Location
    Croatia,Pozega
    Posts
    37
    Thanks for help.
    I started rewriting externs... need to get rid of those unresolved externals.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Multiple Modules
    By rwmarsh in forum C++ Programming
    Replies: 6
    Last Post: 02-18-2006, 04:34 PM
  5. Problems trying to install additional DIMM modules :(
    By Gades in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 05-28-2002, 02:45 AM