Jump to content
  • Advertisement
  • entries
    743
  • comments
    1924
  • views
    584362

Different resolutions

Sign in to follow this  
Aardvajk

350 views

Just a quick update. I've now added support for different screen resolutions to the game. Since it is a 2D scroller with a native resolution of 800x600, it did not seem feasible to mess about actually changing the size of blocks, and I didn't want to display different amounts of the map depending on the resolution, so I'm plumped for just a black screen with an 800x600 viewport in the middle of whatever resolution the screen is.

This might not be an ideal solution but it was really just to address the issue that some laptops I've tested on don't seem to like anything except their normal resolution and it works around this problem.

The next thing for tonight is to decide on a format for a config or ini file that can contain options like screen sizes, a list of levels and so on. I'm considering using XML for this, but I don't know anything about it really.

The other option is to come up with a sort of scriptable config language that supports a kind of registry like tree structure read from a text file that can hold strings, ints etc. The problem with a straight x=y ini format is that one of the things I need the config file to contain is a list of the levels, as well as single values like ScreenWidth or whatever, so I'm thinking about building a static lib that can parse a text file like that into a tree structure of some kind and be queried for values. This could then be used in any projects that require configuration.

Perhaps reinventing the wheel but that's the nice thing about doing this for a hobby rather than a job.
Sign in to follow this  


6 Comments


Recommended Comments

Do you know CSS? If you do I'm using a CSS style script and a custom parser you could use.

XML is good too, but most people can't seem to settle on which way is the "right way" to use it. I've seen a lot of people hassling others over it[shakehead].

Share this comment


Link to comment
Don't really know anything about CSS. I'm really just looking for a way to be able to store single values and lists in a config file that I can easily load into variables and vectors on start up.

I'm going to have a bash at rolling out my own over the weekend since I'm a bit stupid like that. I've quite a lot of experience of writing recursive compilers so I have a pretty good idea of how I'm going to approach it.

I'm a nightmare like that. Between you and me, I've only just started using std::string and std::vector. Don't tell anyone. [smile]

Out of curiosity, how would you use CSS to store application properties? I've been looking at TinyXML earlier but it seemed to have a bit of a complicated interface for what I want.

Share this comment


Link to comment
Actually, probably easier for what I need it for would be to just have a .ini style x=y config file that loads into a std::map<std::string,std::string> and have things like lists of levels as a single string with the level file names seperated by : or | or something, then tokenise that string into a vector<string> for dealing with the individual level names.

The more I think about it, the better an idea that seems for a game config.

Share this comment


Link to comment
Quote:
Original post by EasilyConfused
Don't really know anything about CSS. I'm really just looking for a way to be able to store single values and lists in a config file that I can easily load into variables and vectors on start up.

I'm going to have a bash at rolling out my own over the weekend since I'm a bit stupid like that. I've quite a lot of experience of writing recursive compilers so I have a pretty good idea of how I'm going to approach it.

I'm a nightmare like that. Between you and me, I've only just started using std::string and std::vector. Don't tell anyone. [smile]

Out of curiosity, how would you use CSS to store application properties? I've been looking at TinyXML earlier but it seemed to have a bit of a complicated interface for what I want.


I'm not entirely done with the parser yet, but what I have done now supports stuff like the following (these are the old environment settings for my GUI):

environment
{
Skins-Folder = Skins/;
Default-Skin = Default/;
Default-Cursor-File = Cursors/Default/;
Font-FileName = Fonts/tahoma14;
Font-Size = 14;
Font-Color = argb(128, 0, 64, 128);
}



And then to load it you'd do something like (sorry, this is crappy code but it's the only example I have at the moment):

ConfigFile SkinConfigFile;
SkinConfigFile.LoadScript(GetAppPath() + "environment.dftgui");
ConfigClass* Environment = SkinConfigFile.GetClass("environment");
SkinFolder = *Environment->GetValue("Skins-Folder");
std::string DefaultSkin = *Environment->GetValue("Default-Skin");
std::string FontFileName = *Environment->GetValue("Font-FileName");



But, I need to change this, since stuff like the last two lines can cause errors if "Default-Skin" or "Font-FileName" isn't available. It's actually kind of flawed, since I don't differentiate between types (I leave that up to the user.) The ConfigValue class does however include parsers, so you could do something like:

ConfigValue* Value = Environment->GetValue("Font-Size");
int FontSize = 0;
int FontColor = 0;

if(Value)
FontSize = Value->ParseInt();

Value = Environment->GetValue("Font-Color");
if(Value)
FontColor = Value->ParseColor(); // parses both rgb() and argb().



However, unless you're doing it for work/sale, rolling your own is always a good idea IMHO though (More fun that way[wink].)

Share this comment


Link to comment
Quote:
Original post by EasilyConfused
Actually, probably easier for what I need it for would be to just have a .ini style x=y config file that loads into a std::map<std::string,std::string> and have things like lists of levels as a single string with the level file names seperated by : or | or something, then tokenise that string into a vector<string> for dealing with the individual level names.

The more I think about it, the better an idea that seems for a game config.


I've done this before and it works REALLY well. It's extremely easy to do too.

Share this comment


Link to comment
Your CSS stuff looks really good actually. That was the kind of thing I was vaguely thinking about although I've decided not to go so complex for the game I'm writing at the moment.

I reckon I'm just going to write a class that wraps a std::ifstream and just supports >> std::string but instead of just parsing whitespace-seperated tokens, will parse any list of tokens enclosed in { } into one string with some kind of terminator character.

So the config file can look a bit like


ScreenX 800
ScreenY 600
SoundHardware 0

Levels
{
levels/level1.orc
levels/level2.orc
levels/level3.orc
}



so that the >> function would put

"levels/level1.orc:levels/level2.orc:levels/level3.orc"

into the string for the last one. I'll then just have another function that takes a string and a vector<string> as parameters plus a terminator char and break the string up into the vector.

Nice and simple. I can see where your stuff above would be invaluable for something like a GUI with more complex settings though.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!