Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Disch

Pages: 1 ... 6 7 [8] 9 10 ... 15
106
General / Adding a Title screen / organizing code
« on: June 22, 2011, 05:57:58 am »
Another polymorphic approach would be something like this:

Code: [Select]

class GameState
{
public:
  virtual ~GameState() { }
  virtual GameState* Run() = 0;
};

// .. derive different game states from GameState, such as
//  TitleScreen, Settings, MainGame, etc

// .. then in main:

GameState* currentstate = new TitleScreen;
while(currentstate != 0)
{
  GameState* nextstate = currentstate->Run();
  delete currentstate;
  currentstate = nextstate;
}



The idea is that each game state then returns an instance of the next state to run.  So TitleScreen::Run would return "new MainGame;" or "new SettingsMenu;" or something depending on whatever options the user took at the opening menu.

Just have run return 0 when you want the program to close.


EDIT:  another advantage of this is that you can nest states.  For example, you could call Run from inside other Run functions (for instance if you wanted to open the SettingsMenu from MainGame, or something like that).

In which case returning 0 would mean "go back to the previous state" instead of "close the program"


EDIT 2:

Quote from: "Kulade"
Also, is that something that a beginner should be worried about?


Yes.  Code organization is a big deal.  I can't tell you how many projects I've ultimately dropped because over time the code just became too messy to work on any more.

107
Graphics / which image types work with "image.LoadFromFile()"
« on: June 21, 2011, 12:38:10 am »
Why do you suspect that?  Is LoadFromFile failing?  (it will return false if it fails)

8 bit pngs are supported

108
System / Unicode with cout command...
« on: June 20, 2011, 08:11:20 pm »
Quote
The problem is the return type: std::string is not suitable for multi-bytes encoding such as UTF-8 or UTF-16. So what should I return?


std::string works just fine for UTF-8.  The only thing is that the length() is not really going to be the length in codepoints.  But that's a minor issue

As for UTF-16, std::wstring would work even though wchar_t is sometimes larger than 16-bits.

109
System / Unicode with cout command...
« on: June 20, 2011, 07:32:55 pm »
Quote
Many people and many functions work with a system-locale-specific std::string. Because that's the only way to use std::string without having to care about the encoding.


Point taken.

Quote
The Windows API can work with UTF-16, true. But when you print to the console of read a text file, there's no UTF-16 anymore (the default on my machine is CP-1252, which is a superset of Latin-1, which is a subset of UCS-4).


Reading text from a file is dependant on the encoding of the text file.  Text files can certainly be UTF-8 encoded on any platform.  Maybe I'm missing your point there?

As for printing to the console, you can print Unicode to the console if you go through WinAPI functions (like you said), it's just that the standard lib doesn't cover it for whatever reason.  Of course I'm not suggesting that SFML try to fix Windows' version of the standard lib.

But yeah, I get your point.  For working with the standard lib, you need a specific locale encoded string (yuk).  So yeah, I'm wrong.  You're right.


I still think sf::String should have conversion to Unicode functions.  I was a little surprised when I didn't see any.

110
System / Unicode with cout command...
« on: June 20, 2011, 07:12:55 pm »
Quote
The function converts to std::string using the encoding defined by the current locale.


In that event, the function is not poorly named, it's just ambiguous because it's platform dependent.

Personally, I would remove it altogether, as platform dependent behavior kind of defeats the point of using a crossplatform lib like SFML.

Quote
Linux has moved to UTF-8, but Windows is still stuck with extended-ASCII codepages.


Not true.  Windows has been on UTF-16 since at least NT 4.0 (1997-ish?)

Granted, the C++ standard libs are oblivious to this and tend to not support UTF-8 when printed to cout (or passed to fopen, etc), but that's not an issue that SFML needs to concern itself with, IMO.

111
System / Unicode with cout command...
« on: June 20, 2011, 06:44:48 pm »
Well what does the function actually convert to?  And how does it do it?  (can't check the source right now because I'm at work).


Personally I fail to see the point in doing anything besides Unicode, as Unicode is all encompassing.  Especially since sf::String seems to be UTF-32 internally.  Code-page based glyph mapping is kind of like a legacy thing.

112
Graphics / render window Clear to colour not working
« on: June 20, 2011, 04:22:50 pm »
Laurent was looking for a minimal program that reproduces the problem.

IE:  give us something that we can compile and run and see the problem for ourselves.

What you posted isn't enough, as that problem might be elsewhere in your program.

113
System / Unicode with cout command...
« on: June 20, 2011, 04:20:54 pm »
Quote
ToAnsiString()


Then that function is poorly named.

114
System / Unicode with cout command...
« on: June 20, 2011, 06:57:49 am »
looks like sf::String doesn't have a ToUTF8 function (Wtf?  seriously?)

So you'll have to go through the sf::utf utilities.

Read:  This code is untested:


Code: [Select]

std::string ToUTF8(const sf::String& original)
{
    std::string str;                        // the final UTF-8 string
    str.resize(original.GetSize() * 4);           // worst case scenario:  4 bytes per codepoint

    std::string::iterator last = sf::Utf<32>::ToUtf8( original.GetData(), original.GetData() + original.GetSize(), str.begin() );
    str.resize(last - str.begin());

    return str;
}



So then if you want to put a unicode codepoint in the string and print it....

(again untested):
Code: [Select]

int main()
{
  sf::String example;
  example.push_back(0x304D); // U+304D = き  (Hiragana Ki)

  std::cout << ToUtf8(example);
}

115
System / Unicode with cout command...
« on: June 20, 2011, 06:05:54 am »
It depends on the system you're running.  On windows, outputting Unicode characters to the console is unreasonably difficult.

If you're only concern is Linux, then you should be able to output utf-8 just fine to cout.  It worked for me on Ubuntu.  I can't imagine that other distros would be different.

116
SFML projects / Isolation
« on: June 19, 2011, 10:21:58 pm »
I just run out of ammo right away.  How do you get more?

117
SFML projects / SFSL - SFML File System Library
« on: June 16, 2011, 11:04:11 pm »
Thanks, fekmon.  That actually is very useful.

I'll definitely check this out in more detail when I get the time.

118
SFML projects / SFSL - SFML File System Library
« on: June 15, 2011, 04:15:45 pm »
I hadn't, but I will review it when I get some time.  It does seem like it would help, but it also seems to be lacking some features I want.

But I didn't look in detail.

119
Feature requests / ResourceStream class for custom resource loading
« on: June 14, 2011, 04:58:40 pm »
Thanks.  It's great to have an upload site that doesn't suck.  =)

120
Graphics / MouseMove.X always returning 0...
« on: June 14, 2011, 07:27:40 am »
Since it's a mouse button event and not a mouse move event, try Event.MouseButton.X and Event.MouseButton.Y


EDIT:

Also, using pow to square stuff should be a mortal sin.

pow(x,2) <- bad
(x*x) <- good

using pow for this is like driving a small nail with a sledgehammer.


EDIT 2:

Also, another optimization tip for your future reference:

You can avoid the sqrt call for this kind of collision if you square the radius.  Remember that the actual theorum is a*a + b*b = c*c.  Note that theorum only has a sqrt if you try to solve for c, which is unnecessary.

Code: [Select]

// assuming x and y are the distance between the point and the circle center
// assuming r is the radius of the circle.

// bad:
return sqrt( (x*x) + (y*y) ) <= r;

// better:
return (x*x) + (y*y) <= (r*r);

Pages: 1 ... 6 7 [8] 9 10 ... 15
anything