# Unwise owl

Member

340

158 Neutral

• Rank
Member
1. ## Oddly Shaped 2d Maps

Quote:nsized tile data 8 bits of repetition That I know, but you're right if there's only one very common value we want to compress (such as for emptiness) n-sized data will do just fine. This is especially true if inside the n-sized tile data a one bit flag is included, which disables the repetition data provided there's no repetition. If that's the case n-size data will at max cause a 1 bit increase per data item (which in pratice is 0 if you don't use that bit for other purposes anyway). Still, having lots of RLE data to step through to access a random tile even with indices for one dimension can be ugly. And I never liked iterating through RLE data overall because drawing algorithms turn less staightforward. (I wrote a fairly simple RLE blitting function with destination and source rectangle clipping and the result looked not-too-nice. Though it depends on the programmer what's perceived difficult, I'm a mere hobbyist. :P)
2. ## Oddly Shaped 2d Maps

Or just make a number of rectangular "map regions" with a shared global coordinate system, then offset each coordinate to get the local coordinate in that region. For example, let's say you want a level looking something like this: 11111111111111111 2 2 2333 You can divide it into three rectangular areas and call them 1, 2 and 3. Figure out their relative position to the global coordinate system and add/subtract as necessary to place them correctly when you draw the tiles. I suggest monsters and other non-tile tied entities use the global coordinate system though and only are converted to local scales for collision detection. (By the way you can calculate/store what region(s) (if at border) an entity is in and only test for collision detection in those.) An example (should be abstract enough even if you're not into C++): struct MapRegion { Vector2Df offset; //into global coordinate space Vector2Di size; //width and height in tiles/cells of region, whatever you call them MapCell* tileData; //points to 2D array }; void TranslateToLocal(Vector2Df& position, const MapRegion& region) { position -= region.offset; } void TranslateToGlobal(Vector2Df& position, const MapRegion& region) { position += region.offset; } What I see as a disadvantage of this technique in comparison to RLE compression is region transitions (if you try to group entities by region, what happens when a big entity stands in two or more?). But rendering/collision detection doesn't require much else than iterating through all regions doing what you'd normally do with a single 2D tile array. RLE compression makes finding specific tiles a bit more CPU intensive as you'll have to iterate through your RLE data from whatever indices you keep (maybe rows or columns). It also means you can only represent your tile with a byte (or a short) value describing the type and nothing else. [Edited by - Unwise owl on May 3, 2006 2:44:50 PM]
3. ## game of life...

Isn't it possible to keep two exactly the same sized bords in memory, then having two pointers called currentBoard and temporaryBoard respectively. Then you would on update switch them and step over each square in the currentBoard, quering for the corresponding number of neighbours in the temporaryBoard? For any other functions after update it's just to check the currentBoard pointer for the most recent board. This way you avoid two memory copies (if that's an issue, shouldn't be anyhow with small arrays).
4. ## 2D Game Programming

Quote:Original post by Unknone Don't get me wrong, SDL and Allegro look great. But I don't want to get into the habit of using another 3rd party library or engine because then you can't program properly without them. That's why I don't use graphics engines and anyway, I've already looked at OpenGL. But I need to go to the Win32 API to learn certain things, such as how to load up a bitmap WITHOUT any engines or anything. I will still probably learn SDL and Allegro, but that will be after I have a reasonable to good knowledge of the API. Thnx for the help though. SDL is far from an engine. I'd call it an API and nothing more. In my own game a have several layers of abstraction on top of the SDL layer (eg. I'll never end up calling SDL_X directly but only through my own graphics functions). SDL is very much bare minimum in certain regards, I still had to write my own image format loaders and direction pixel manipulation. And, you don't need to learn the Win32 API straight down; it just isn't necessary because it's an antiquated piece of software soon to be replaced anyhow. The only thing necessary is to get a good grasp of C++ while having fun. Using SDL to program a 2D game can be.
5. ## How many c++ classes per file

DarkZoulz, you live in Bålsta? Anyway on topic, it depends like it has been said. I usually only have one "main" class per file, but when this class has some small utility classes/structs to support it I often put them into the same header (and .cpp) files.
6. ## How long did it took you to learn C++?

I learnt most C++ syntax issues in maybe two years (my excuse is I've been doing this in my spair time and with huge gaps in time when I'm programming and when I'm not). I've been going on for maybe 5 years in total now, but I still suck on the code design aspect. I usually end up having to rewrite code several times because I planned something wrong (or didn't plan it at all). Bottom line, like everyone else here says don't worry if you don't get immediate results. :D
7. ## Planning Ahead for Multiplayer...

Quote:Original post by hplus0603 Quote:should the server keep a separate copy of the world separated from the client? In my opinion, it absolutely should with the model that you suggest. It doesn't have to in the Warcraft-3-like setup I previously described, because all clients (including the client that's serving) will have the exact same game state. Okay, then I'll work with some kind of "displayable world" instead that's closer connected to the graphics output (alright since I needed that an inteface to draw world entities in the first place). Quote:You can decide to send object creates, deletes, and occasional updates if that's what you want to do -- it's certainly simpler than getting co-simulation to work right. The main draw-back is that whomever is hosting the server can cheat in ways the other clients can't, because it can send authoritative updates about the entity states. Plus bandwidth -- entity updates will take bandwidth. There won't be all that many entities that need frequent updating so I don't think bandwidth is an issue. Cheating is an issue obviously, but my game is not mainstream and I don't expect people to play with people they don't know. (Instead they can exclude cheaters.)
8. ## Savegames and My Documents

I agree with the OP. My argument is simple: A game should keep to the folder I install it in. It should NOT start spreading files in any other directories. I hate not having control of my computer, but instead some not too clever programmers/designers try to impose their organizational ideas upon me. It doesn't make things easier at all, I still have to browse to the damn thing unless I set up a shortcut (it's no excuse that Windows already has set up shortcuts to My Documents).
9. ## Planning Ahead for Multiplayer...

Okay, so what I gathered from your posts: Assign each unit/element/piece an identifier: Actually I was already doing this, but it's good to know I'm doing the right thing. Some identifiers are indices into static areas (of course bounds checked), and some refer to dynamic elements such as the armies I was speaking about. Use one protocol: I'll go with TCP then because communication shouldn't have to be very intense due to the game's nature. I won't support server migration: I'll just be convenient and say "set autosaving on the server to the most frequent interval". I'm a bit confused about the client/server concept though (I know what it's defined to be but still). Who's responsible for holding the game world data? Some other storage class (CWorld is what I had until now) with client/server code only interfacing to this data (both sharing in case of singeplayer, else there is just one), or should the server keep a separate copy of the world separated from the client? It's not decided also whether I should make synchronization across multiple machines (although it is what you seem to recommend for an RTS). My counter-reasoning is the client in the case of multiplayer should be able to maintain a reasonable state of the world merely by keeping track of object additions and deletions, and frequent updates of those that are visible. (This game only features a low number of heavily dynamic objects. Most objects just sit in place until you do something to them.)

11. ## Parsing Half Life 2 Map Files

Quote:Original post by Gaheris The question is stupid, but did you have a look at the Source SDK? I'm not sure if it has any information about the uncompiled map files though. Can't recall that. Probably they don't want people using their Hammer editor for other games since that's what the license says you're not allowed to...
12. ## Is this legal syntax?

Just tried something like this after getting curious: int a = 1; int* b = &a; int** c = &&a; int*** d = &&&a; int**** e = &&&&a; Doesn't seem to work... Nor does: int a = 1; int* b = &a; int** c = &(&a); int*** d = &(&(&a)); int**** e = &(&(&(&a))); (Returns same error as if I whitespace the ampersands.) Only int**c = &b; etc. works. Not too surprising as I'd expect an expression such as &a only to generate a value at a temporary address, which in turn you cannot take the address of.
13. ## Connecting UI Code with Game Code

Ok, I've decided to throw out the damn CAction base class attempt and do it with mapped function pointers instead like in your example, with or without Boost (as of yet undecided). Having a class for each command just becomes incredibly cumbersome since the action should have complete knowledge of the class it's supposed to modify. Referring to a member function seems like a much more pretty solution.
14. ## Connecting UI Code with Game Code

I'll have to look up Boost, I see it frequently around here. Am I correct in that boost::bind is a global function registry? Interesting, but it makes sense because one registry is really only needed...
15. ## Connecting UI Code with Game Code

I've programmed the early stages of a fairly typical tree-based UI for my game. That is, for every parent window there are child windows (that can be derived sub classes for buttons etc.), and when I call render and collision detection functions(click point test) these recursively down the tree (collision detection front to back and rendering back to front). Now, I run into a problem regarding events. I know how to make them, but I don't know what object should be responsible for 1) generating the events, that is, checking for clicks and triggering events, and 2) how to execute certain game code based on what event happened to which window. To solve the former problem I guess I could let the cursor code invoke click events, but that means it will have to know about what part of the UI is active at the moment. (There are two distinct states: "Menu" and "playing".) I have a menu object; I could let it deal with it, but that'd require to have a similar object for the actual game. Perhaps I should consider creating a "CPlaying" or "CGame" object and let it and "CMenu" derive from a base class that has functions that the main loop can call if there was input? To solve problem nr. 2, I was thinking of having a "CAction" class that would be derived for each action that can be trigger by an UI event. There would be some sort of central registry (perhaps one for CMenu for example) where they were linked to an event key. Once an event triggers it would look into this registry and execute a virtual function in the CAction pointed to. I see multiple potential dependency clashes here though. Comments?