Advertisement

Making my own engine...

Started by February 11, 2001 02:32 PM
8 comments, last by MeEatCows 23 years, 11 months ago
I''ve got the main idea on how to make a isometric game engine but I have a few questions about it. 1) When the player starts to play do I then draw all of the surfaces that will need to be used for the game then load the images and paint the surfaces as needed? Or what should I do it? 2) I havent really seen anything that handles with how to load a map and then make it so you can use the surfaces in other things. How do I load all the surfaces and then be able to use the variables names in other functions? Thanks
Im not too sure what you mean but ill try and answer you. The way I do it is load in bitmaps to the surfaces i am going to use (my game isnt too big so I dont have to worry about only loading in the stuff for 1 area). Then draw to the screen what the player can see (update it when he moves obiously). Now with the reuse of surfaces- if you are going to use the same image then you just copy the surface to the back buffer. if you want to put something else on the same surface then you can either delete it and create a new surface named the same or clear the memory at that address and then reuse. erm thinking about it im not sure this is what you asked for. well if it helps then i am glad if not then i am sorry.

Just my thoughts take them as you will.

"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Advertisement
I hope I can answer your questions; they are a bit confusing. I don''t think you really know what you are asking. I see question 1 asking when you do the drawing updates.

This is what I do. Every time through my main loop I do what I call "drawMap." This function looks at where the current window is in relation to the game map. As you know, the real game map is much bigger than the window that you are drawing to. This means that effectively you have a sliding window over the game map, only drawing a part of the map at one time.

As a player moves you update the position of the sliding window in relation to the main map. Then when you call your "drawMap" function again it sees the new position of the sliding window and knows to draw the new part of the map.

Your second question ties right into this. Your map is an important item and I''d store a 2Dimensional array of what is in each position.

I''d also store the images that get displayed in the map in a separate, one dimensional array. So each cell of the map pointt to, or contains the Identification number for the graphic that you want to display. This means that you mountain image, for instance, only resides in memory in one place. The map cell just says what graphic (the mountain image) is supposed to be displayed. Then your drawing function will get the image and draw it in the appropriate place in the sliding window.

I hope this helped. Feel free to ask more.

RandomTask
Sorry about not being to clear on what I wanted to know.. maybe this reply will clear up what I was asking. My question is pretty much how do I build a dynamic sized map? When the game actually gets passed the main screen and to the game it loads the map file. For this example lets just say the map is 1000x1000 squares and only 500 are visible on the screen at all times. Would I create the 1000x1000 surfaces when the game loads or would I just draw the 500 surfaces that will be shown on the screen? Or how else should I do it? By the surfaces I mean the triangle strips that the textures will be added onto.

If I should creat the 1000x1000 surfaces how would I make it so that a differnt function in the game could add a texture to the surface? The surfaces would have to be created at runtime and not coded in so that would be the variables that hold the surfaces couldnt be global varibles hence I wouldnt be able to use them from another function.

If I only create the surfaces that would be visible on the scren do I just make static ones coded right into the program or do I keep creating and removing surfaces as needed? If I have to create them as needed how do I handle when a character moves? For example a monster moved onto the screen and you create the surface for it, that surface would be above all the other surfaces so it wouldnt work right.. the monster would be moving around ontop of all of the stuff.

If thats not any better please let me know and I''ll try to clear it up some more.
Just to restate my two questions again:
1) When the map is being drawn for the first time do I create all the surfaces that the game will need or do I just create X amount of surfaces and reuse them? Or how else should I do it? When I say surfaces I mean a surface without a texture..

2) Ok my map is being drawn for the first time. My program reads the map file and finds out that we need to creat X amount of surfaces.. how do I make them? I know how to make one surface but each surface needs a variables name correct? The variable would need to be global so other functions could use it correct? How would I create the global variable at run time?
Hi,
I think confusion is arising from your use of the word surface. My understanding of the word surface is related to the DirectX surface ie. an area of memory allocated for graphics.

Now, I expect you will have a set of bitmapped images to draw your map with. Unless you intend to have one for each cell in a 1000*1000 map, which is unlikely, you will only have a small set.
These bitmaps would typically be loaded (to a surface) before they are needed, possibly before the game starts.
You will then need a surface on which to draw (and any backbuffers you need). The amount of the map you draw at any one time depends on the size of your map and the constraints of your machine. For example, I would think that drawing a 1000*1000 map would suck up a fair bit of time if you have to do it often. In this case you would draw a smaller section of the map.

Since your question is fairly ambiguous, I can''t really answer any more specifically. In summary however, bear in mind you need 1 or 2 surfaces to store your bitmaps in, 1 primary surface, 1 back buffer and perhaps another 1 or 2 if you want to draw things in advance.

One more thing... If you want to create an arbitary number of surfaces, you would use a variable length data structure (like a list or vector).

hope it helps and if I have missed the point, sorry :-)

-DeVore
Advertisement
Let me make my question as simple as possible.. how do you make new surfaces while the game is running? I dont mean how do I add textures or anything like that.. I know how to do all of that.. I''ve got everything covered but this one proble. I know how to make surfaces but when I make them I usually need a variable.. but if the game dont know how many variables its going to need how do i handle that?
So basically what you''re looking for is an array of dynamic size. There are several ways of doing this, though there are two main solutions:

1) Linked lists. You will need a structure that holds information about the surface (like the pointer to the DD surface) and a pointer to the next item in the linked list.

2) Actual arrays. There are templates in the STL (C++) for doing this, or you could write your own implementation. What they do is basically: keep a pointer to the array as well as an int holding the length of the array. When you add a new item, you have to alloc a new memory area for the array (which is slightly bigger than the old area), copy the old contents over, and delete the old memory area for the array. You can then add new items to it.

If this doesn''t help you, you should tell us why you have to create surfaces dynamically (i.e. what are they needed for).

cu,
Prefect

---
Sanity is the trademark of a weak mind.
Widelands - laid back, free software strategy
Here''s some semi-pseudocode

  // you should have some sort of tile class or structure// defined in order to stroe all of your tile data, such// as walkability flags or whatevertypedef struct tagTILE{   DWORD flags;   // other data members go here      LPDIRECTDRAWSURFACE7 surface;} TILE;// simply declare a pointer to a TILE struct. This will// later become an arrayTILE *globalTileArrayPtr;bool LoadTileSet_or_Map (){   // in your tile set/map loading routine you should be able   // to determine how many tiles you have. If you don''t have   // this info in your file format, you should include it     Read number of tiles from file;   // now you allocate enough memory to store all the tiles   globalTileArray = (TILE *)malloc(sizeof(TILE) * numTilesInFile)   // later when you are loading in your tile data, just   // create a new surface for each image like so   globalTileArray[currentTile]->surface = CreateNewSurface ()      // copy the image on to the new surface and you''re all set}  


GamesToGO: The Console Gamer''s Paradise
lol..boy theres some confusion here.

aka john
Never give up. Never surrender! -- corny?...yes.
Capt. James Tiberious Kirk -- great guy. Guess he got that nick from playin Tiberia a lot.

This topic is closed to new replies.

Advertisement