Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Top Level Game Structure

Author
Message
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 29th Oct 2003 18:19
To plan and design a game is mostly an exercise of avoiding traps and bad designs.

But is there a guide line of a structure as such?

All programs have a Main but in DB I noticed that the code seems to fill and loom through that main loop. What if you need to add different parts, screens and sections?

There must be a structure that is generic!

I hope some of the most experienced ones, like people who made Starwraith or something similar could give us some of their "lights"!

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 29th Oct 2003 18:48
DarkBASIC is unstructured as such, but it can all be grouped into subroutines or functions. Calling these for different parts of the game, like levels, is usually used.

I would be unstoppable if I could just get started...
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 29th Oct 2003 19:34
yes, have little or no in-line code in your game loop, break out to subs and functions for a more modular design. It will make your life easier

-RUST-
Codger
22
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 29th Oct 2003 19:52
One approach is to make your "main loop" the menu then branch from there as the user makes decisions or advances.

Function Menu()
if mouseclick() <> 0
UserInput = CheckScreen()
Select UserInput
Case 1 : exitGame()
Case 2 : LoadPriorGame()
Case 3 : PlayBeginer()
Case 4 : PlayAdvanced()
etc..

Then make sure the Subfunctions return to main menu for additional input

System
PIII 650 MZ H.P. Pavillion
394 Mem GeForce 4 400MX
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 2nd Nov 2003 23:19
If there was a structure, a recognisable structure that would describe your project approach when it comes to coding, would it be:

a) Star (main first and all stems from there)
b) Tree (main is the root, everything branches out)
c) AdHoc (make the diagram as it comes)
d) Unstructured (small code, mainly a demo or a code snip)

Elaborate to your answers if you can. Maybe this forum could have a voting flavour of it...

Sory if I am being pendandic

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 3rd Nov 2003 04:17
Is DBPro more structured other than DBC?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Nov 2003 04:32
it's roughly the same as it is all procedural basic - you can make your code as structured or as cluttered as you like. I suggest using subs and functions anywhere you can, and INDENT your code as to make it as readable as possible, use comments all throughout your code - trust me - if you write some long/complex code and then come back to it six months later you will thank yourself for the comments!

-RUST-
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 3rd Nov 2003 04:59
How do Subs and Funtions make it more structured?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Nov 2003 05:14 Edited at: 3rd Nov 2003 05:16
well, instead of having a slew of inline code, you can break out everything to it's own sub or function so the code is A)more readable B)easily navigated by jumping to functions and labels from the ide and C)reusable, functions can be made generic and then you alter the arguments to pass in whatever is needed at the moment and can be called from anywhere in your code - the same goes for subs but in dbp subs don't accept args.
you'll find yourself NEVER using silly open-ended "goto" commands!
GOSUB-RETURN and
strMyVar=MYSTRINGFUNCTION()

-RUST-
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 3rd Nov 2003 05:36 Edited at: 3rd Nov 2003 05:44
Yah, goto loops are really unstructured and I don't ever use them in a lot of my code. Also, when I get stressed about my program being buggy, I just start comenting on everything.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Nov 2003 05:51
code reuse is very handy and efficient when making large programs. Oh, and you should never have to use GOTO.
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 3rd Nov 2003 06:05 Edited at: 3rd Nov 2003 06:07
Well, you would if you had something you wanted to repeat more than once, like making a calculator:



I don't know a better way, but the goto is kindof a lazy way to do things.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Nov 2003 06:37
nope, goto should NEVER be used, especially in a language that has subs and functions...



-RUST-
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 3rd Nov 2003 06:48
Then why did they even make the GOTO command in DBPro/DBC if it should never be used, it doesn't make sense.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Nov 2003 06:52
ha ha, goto has been around for years and years from older languages (lower level) that didn't have a concept if sub routines or functions-goto was the only way to jump around.

-RUST-
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 3rd Nov 2003 06:56
So GOTO evolved into Subs?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Nov 2003 07:00
well I don't know for sure but it seems logical. But shouldn't you know all about this as you know C++,java,vb,html,dbp and TI like you said in another post? or did you mean you have touched upon these languages and are still beginner at them?

(not trying to be rude, just asking)

-RUST-
genius
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: Utah, USA
Posted: 3rd Nov 2003 07:06 Edited at: 3rd Nov 2003 07:12
Yeah, I'm just skimming the languages, like I'm trying to learn C++ graphics(hard) . But, since they have Subs now, what is the need for a GOTO?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 3rd Nov 2003 07:47
I don't know why it's still there, just a remnant of BASIC I guess. The minute they pulled it out some genius somewhere (no pun intended) would find a reason to leave it in there. I have been coding for years and have not used goto since atari400 basic, but even then they had gosub/return. I guess I was all 13 and noobish.

-RUST-
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 13th Nov 2003 17:39
no using goto is a prerogative really. Purists dont use it, purists on methodologies like OO i mean.

I dont use it because it breaks the control flow by jumping in and out of functions. I also avoid the exit or break command. It is as bad.

I would like to thank all those who respond to my question. I was not clear enough on what it was I am looking for. Still all those thoughts are good.

What I want to develope is a methodology on writting a game. I do follow certain paths when I develop at work, client server applications, database back end driven programms and such. For games I still try to figure out what sort of structure I should adopt. Unfortunetly DB is not OO. Which it is a pain.

what I know for start is that you need a loop.

Do

Sync
Loop

The screen refreshes and you better have everything ready by the time it does!

Still sometimes I want to leave the loop going and have te flow go prepare something else, as if it is doing it backstage. At this point I jump to a module that interupts the seamless of my game...

Do you see where my problem is?

I am not looking for a solution, it is just a discussion subject. Every design has it's particular problems and you find a way to work around it. But if someone has an advice please let me know!

=C=

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 13th Nov 2003 18:34 Edited at: 13th Nov 2003 18:35
Well from some of the things you mentioned you are in need of threading ability which dbp doesn't expose to the programmer. You may want to look into using vb.net or C# or C++ with directx9 sdk which includes classes for Managed Code. You would be programming in a powerful OOPL (any of three above) and you would have the ability to do whatever you wanted thread-wise.

For most games, even very complex ones dbp is more than you'll ever need - but for me I want to move to VB.NET for game coding as it is my default language and now has the ability to work kind of how dbp does, but more directly, with the DX9 API - not to mention the main reason it is OOP.

-RUST-
waffle
22
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 13th Nov 2003 19:36
one item that everyone here seemed to miss...
INCLUDE FILES
use one file for each major IDEA.....

example...
string functions in the STRRING.DBA file
INI file functions in the INI.DBA file
Internet code in the NET.DBA file
Map functions in the Level.DBA file
Collision code in the Colide.DBA file
GameMain code in the Main.DBA file
Debugging Code in the Debug.DBA file

also, use Labels as bookmarks
Place a label in key areas (for User Types) and you can find
them fast using the label list

Also, remember to place comments at the top of each module
to explain what the module is for.

Also, place comments at the start of each function to explain its purpose and what each parameter is for and what the reply means.

Try and minimize the use of globals inside of functions. You should try to get functions to need nothing thats not inside the module the function is in. Also, each module should not use globals that are defined outside of that module. This makes each module reusable in other projects.

internet gaming group
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 13th Nov 2003 20:56
nice programming 101 tutorial, what exactly did it have to do with what =C= said, and my reply?

-RUST-
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 14th Nov 2003 14:10
Thanks for the tips. As I said, I hope people come up with issues and ideas. I could easyly say:

Quote: "I've done that! thank's for the tip anyway!"


But I won't, i like the idea with the labels as book marks and yes good to mention the old include command. It does make the brain hurt less

This is exactly the kind of posts I wish to see... More ideas please.

Also thanks for the great top level info regarding C++ and .net I am planning getting into it by doing the MS exams soon. Direct X seems to be quite the way!

I still wonder tho. DBC should have a methodology to make multythreading work for it! I mean there must be a way of writting to make it work! It work as is but I can't seem to make it click 100%...

Any genius ideas?

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 16th Nov 2003 02:04
In defense of the GOTO command, sometimes it is handy when you have an exception to the rule to simply use a GOTO statement. The most common example that comes to ming is when you're processing a loop and some data invalidates it. I'd reserve it only for exceptions instead of making it a regular practice to use.
--
TAZ
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 17th Nov 2003 11:34
The rule is that when it comes to games development the rule book goes out of the window (sometimes).

A game is a complete system, once it's done it's done. A complete game doesn't have to have readable code not even maintainable (provided it is bug free)... It only has to have fast executing code. So all the dirty tricks are valid.

I am currently looking at removing a big stack of functions calling functions and see if it makes a big impact on speed. Particularly I am looking on the impact the case command might have...

The problem in a nutshell is that I have to decide to create 5 objects. they all have to be from a choice 10 objects. This is where the case comes to play.

Also apart from that I need to update a few arrays too. All that makes my code freeze for a moment or two...

If you ask for a code sample you'll be right but there is nothing i can post here because it is a whole system developed, not a few lines...

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
waffle
22
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 20th Nov 2003 00:09
DB/DBPro do not support theading. In fact, you can't even obtain a procedure address to pass to a DLL that can create a thread and call the procedure. Having said that, what DB/DBPro need are threaded procedures that handle FTP internet access. I have some I do for myself, but it would be nice if it was native.

Also, for game use, I don't really see a need for threads. One theory that does come to mind would be to setup a memblock, pass the memblock to a DLL that creates a thread that uses that memblock to move an object independantly of the main loop.... why though? its movement would be unreliable as its not under direct control. Sure, the main loop could change parameters in the memblock or read data from the memblock for status stuff, but the rate of responce would depend entirely upon DB/DBpro permiting the OS to allocate time slices to the thread, which will slow the game.....

internet gaming group
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 8th Dec 2003 14:25
Well, maybe I got the multythreading issue all mixed up. I am pretty sure one shouldnt have to worry about threading the game. It is all down to number of processes ber frame. That is what slows me down.

For instance. I want to make an function that calculates the shortest route between two 3D objects, on my 3D map. I have some sortest path algorithms but when they kick in it slows down my game. They simply take too much to run. I would like the rest of the game to go on hapilly and keep the show running but it wont happen the way the algorithm is at the moment.

I need to redesign my navigation screen. That's all and take under consideration the frames it takes to calculate!

Any comments...

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
waffle
22
Years of Service
User Offline
Joined: 9th Sep 2002
Location: Western USA
Posted: 8th Dec 2003 15:25
use precalculations for time consuming bits.

Lets say you have a map (100x100) with 1000 hot spots with stuff in the way.....

Outside of the game you create an array (1000,1000,2)
where the parameters for the array mean (atHotSpot,destHotSpot,Value)
with Value being a #constant to return a value...
0=X position
1=Z position
Then, for each "hotspot" you check for an unrestricted route
to the nearest other hotspot for destination hotspot

Then Save the array
In the game, just read it in.

Now comes the tricky part.....
You need to have "hot spots" everywhere. When an critter is not at a "hot spot", there must be a nearby "hot spot" that it can get to. Then the critter simply goes there and follows the other spots as if they were waypoints. Also, the best way to optimize your hotspots would be to do it manually. Sometimes you need to go south to go north.

This is an example of how to move intensive operations out of the game loop.

internet gaming group
=C=
21
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 9th Dec 2003 17:25
Yup I agree on the precalculated values. I try to avoid big loops of the "for i=1 to x... next i" type. They are very costly...

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy

Login to post a reply

Server time is: 2024-11-25 20:41:55
Your offset time is: 2024-11-25 20:41:55