?
Solved

Modularize

Posted on 2003-03-20
12
Medium Priority
?
386 Views
Last Modified: 2010-04-04
Imagine a simple game that runs with severla units that runs on a single form (that belongs to main unit). Imagine in the future we want to develop a second episode of the game, so we want to add more units and another game form. What is the best way to be able to release the first game, and later on add the second episode??
I mean, a good method of modularize the game. Each episode will need its own form and own units (functions, classes, etc..)
0
Comment
Question by:patroclus02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 3

Expert Comment

by:emadat
ID: 8177338
Implement the main form as a front end that does the following:

- Open an INI file -or the registery- to enumerate all installed episodes.

- List all the episodes for the user to select from.

- Each installed episode is a DLL having some minimum predefined function like -for example-:

    * DrawMenu function: Given the handle of the main form, draw the game menu.
    * Each menu item is linked to a function in your DLL by its index to avoid playing with function names. You can give each function at least one parameter: DC of the main form Canvas.
    * StartGame function: Given the DC of the main form Canvas will draw that game and control from there.

Your main form can have a function that can check on a URL to find if there are new episodes. if any, then it will download the DLL, download its INI or registery keys, and then insert these keys into the registery or the INI file.

This is what came to my mind at first glance.

Emad
0
 

Author Comment

by:patroclus02
ID: 8184467
I see.
But this way I'll get all filled with dll's, I mean that make all the game functions in dlls would be a lot (and also more difficult, don't you think?? from dlls I have no access to any program variable, for example, except those which are parameters). Also I need to intensely use some especific Delphi components (for DirectX usage), and from dlls I can't.

Isn't it another way? Are there any solutions?
0
 
LVL 1

Expert Comment

by:FrankTheRat
ID: 8203713
I think that it's a mistake to think of game 'units' and Delphi 'units' as somehow equivalent.

If you look at the architecture of an older game like DOOM (from ID - I use this example as I'm familiar with it), the DOOM application (or 'engine' as it was known) contains the code that runs the game.
For example, it knows how to make players and characters move and behave, it gives world objects (including weapons and 'shots') their generic characteristics, and defines how the game environment is displayed and how the user interacts with it.

However, the actual 'world' that constitutes the game 'unit' is defined in a separate data file. This describes the actual objects that exist in the unit, what skins to use, where the light sources are, and any extra character behaviours or events that exist. The DOOM angine then uses this file to run the game.

In this way, anyone can write a new 'unit' for DOOM (assuming they have the correct tools) by specifying a new data file. I did this myself many times, with tools D/L'd from the internet. This does not change the way the DOOM engine itself works.

I do not know, but I assume that games like Quake (also by ID) and other FPS games work in prety much the same way. It seems reasonable to me that most games (particualry those that are based on some form of 'world' simulation) could and/or should be written in this way.

Hope this is of help.

FrankTheRat.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:patroclus02
ID: 8204153
Yes, I know, but the question is precisely how to do that in Delphi for the kind of game I'm planning.
0
 
LVL 3

Assisted Solution

by:emadat
emadat earned 100 total points
ID: 8204439
If you need to do the modularization withou re-compiling and re-distribution of your code; then you're are left with a few options. You have to travel the extra mile and put extra efforts.

For global variables, you can allocate a memory mapped file, and implement a dll that exports some functions: CreateVariable, SetVariable, and GetVariable which can be called from all system modules to deal with your variables at run time.

You can also use Windows Messages to communicate between your applicatiosn and the DLLs.

Regards,
0
 
LVL 1

Expert Comment

by:FrankTheRat
ID: 8205196
Well it depends upon what sort of game you're planning.

Its going to be a lot easier if you can write an engine that allows the game to be defined by a static data file (like DOOM etc). That way, you won't have to worry about DLL calling issues etc.

The other option (of a game definition that can contain executable code) is going to require a lot more thought. I appreciate that you're reluctant to discuss too many details of the game but, if parallels with business computing are relevent (and I think they are), you're not going to be able to design an application architecture until you've got a good understanding of the game itself - obviously we on EE will not be able to help unless we understand the game requirements either.

0
 

Author Comment

by:patroclus02
ID: 8219955
Ok, I now know exactly waht I want.
It is going to have only one episode for now, but it's a game with multiple windows (for example, one for building, one for selling, one for info, etc..). And there's a main window (main form, let's say).
Waht I want is to know how can I do this efficiently (have all variables in main unit and other units access them?, create some objects?, etc..)

did I explain myself?
0
 
LVL 1

Accepted Solution

by:
FrankTheRat earned 100 total points
ID: 8220960
OK, I'm not sure this is the most flexible way of doing it, but you could do this with the above described approach. The obvious limitation is that the views (Building, Selling, Info, etc.) would have to be prescribed (i.e. you would not be able to create new types of view on the fly for future releases).

This may or may not be a problem. Any custom graphics, sounds, etc. for each view can be deployed as part of the game's static data.

Having had a very brief go at this sort of thing myself I would say the following:

1. It is theoretically possible to deploy new code in future updates, but this would require a good understanding of an interfacing technique like COM (for example, to utilise the ability to ask the COM interface what methods it provides). I'm sure there are people in the world that would know how to do this for this sort of application, (not me though...). However, to my knowledge, no one has yet written an infinitely variable game engine (nor indeed infintely variable business application architecture).

2. It will be MUCH simpler to avoid executable code in the game definition, and put all code in the game engine. Obviously you will need to predict all possible variables and scenarios (although not their content), but this will be easier than trying to produce an infinitely variable game architecture.

It's probably significant that all games for which add-in episodes are available (to my knowledge) take this game engine + static game definition approach. The alternatives are attractive but too difficult to make it worth while.

I am lead to believe that there are several books on this subject, although I haven't read any of them.

Good luck.

FrankTheRat.
0
 

Author Comment

by:patroclus02
ID: 8225068
I know, but for the moment forget about different episodes or add-ins (imagine I'm gonna write the whole game as a executable code).
My question is this :
I'm going to use Delphi, and as I have several windows to show, I think it could be fine to use a form for each one of them. Then I Show/Hide them at run-time. Is this right?

If so, how should I structure the variables/objects in order to share all the data?
0
 
LVL 3

Expert Comment

by:emadat
ID: 8225211
You use a common unit in which you declare all your types, variables and common functions and procedures.
0
 
LVL 1

Expert Comment

by:FrankTheRat
ID: 8226304
You could also use frames and a single form. I have to confess I've never used frames but I'm lead to believe that they would be a suitable approach.

Again, like the separate forms, you show/hide them at run time as required.

0
 

Expert Comment

by:CleanupPing
ID: 9316650
patroclus02:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question