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 - Hengad

Pages: [1] 2
1
General / Re: Smoothest possible movement
« on: September 10, 2015, 02:17:42 pm »
Quote from: Laurent
Use vertical sync, or limit your framerate. You're probably getting huge framerates, which means tiny (and unprecise -- sometimes zero) delta times.

Yea I have tried those, setting framerate limit (I tried 60, 80, 120 and 240) just makes it worse. Vertical sync doesn't seem to affect in any way. It feels like it makes it just a bit worse too? I don't know.

Quote from: SpeCter
http://gafferongames.com/game-physics/fix-your-timestep/

Good read if you want to do it "right".

That article have been linked to me few times already, I don't understand it, why is there 3 parametes for integrate function? And also how render function in that article works, it takes parameter too? And when going to that "The final touch" chapter, I have no idea what's going on :)

2
General / Smoothest possible movement
« on: September 09, 2015, 03:48:32 pm »
I searched for smooth movement, and I found that one simple and good way is to use delta time. I tried it, but my rectangle movement is still lagging(sometimes it momentarily stops). Is there any better way? How does professional 2d games handle movement?

My example code:
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(500, 500), "Screen");

    sf::Vector2f velocity(0.0f, 0.0f);
    sf::Clock clock;
    float speed = 200.0f;

    sf::RectangleShape player;
    player.setSize(sf::Vector2f(30, 30));
    player.setFillColor(sf::Color::Blue);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            velocity.x = -speed;
        else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
            velocity.x = speed;
        else
            velocity.x = 0;


        float deltaTime = clock.restart().asSeconds();

        window.clear();
        player.move(velocity.x * deltaTime, velocity.y * deltaTime);
        window.draw(player);
        window.display();
    }
}

 

3
General / Re: Problem with constructors - game development
« on: September 07, 2015, 03:12:41 pm »
After total of almost 30 posts I get the answer I have been waiting for. :)

Only this one thing:


World::World()
: windowManager(windowManager) //This is the initializer list
{
    std::cout << "World constructor" << std::endl;
    //here i initialize tile stuff, no problem, i cut it out.
}
 

It gave me error, but I fixed it by inserting parameter WindowManager& windowManager to constructor.
Now it compiles and doesn't call the constructor twice, thank you.
So it looks like this:

World::World(WindowManager& windowManager)
: windowManager(windowManager)
 

Is that correct way? Or is there something I should do differently?

4
General / Re: Problem with constructors - game development
« on: September 06, 2015, 09:25:56 pm »
Quote from: Nexus
Jesper obviously didn't post those links in order to solve your current problem, but as general resources to learn... I don't think pass-by-reference is the last problem you'll ever encounter.

You are right, but I mean that if this is "very simple" thing and yet hard for me, there is no sense I should go learn from those sources.

Quote from: Jesper Juhl
Here's an object, constructed with some data:

std::vector<int> vi = {1, 1, 2, 3, 5, 8};

Here's a function taking that object by (const) reference and printing all its members:

void f(const std::vector<int>& obj)
{
    for (const auto& elem : obj) {
        std::cout << elem << std::endl;
    }
}
 

Well yes I know how to do it with functions. I don't know how many times I've already said this; I just want to access Vector2f screenDimensions that is in WindowManager class, from both Core and World class, but I want constructor to be called only once. :)

Quote from: Jesper Juhl
Clear enough?

I have not learned c++11, but I understand what you are doing there.

5
General / Re: Problem with constructors - game development
« on: September 06, 2015, 09:00:46 pm »
I can also recommend checking out the following list of links for great learning material and more:
 http://www.redblobgames.com/
 http://gameprogrammingpatterns.com/

I am having problem with this "very simple" passing object by reference thing, and you link some game developing book and algorithm stuff ;_; I tried to search for that object pass by reference thing but I didn't find anything useful and I couldn't get it work by my own.

6
General / Re: Problem with constructors - game development
« on: September 06, 2015, 03:41:44 pm »
I wonder who are this "some people" you are talking about.

Nevermind I did research and many people say it's better to use smart pointers. The guy who said it shouldn't be used was some streamer in twitch who was making cool looking game, so I believed it.

Reference should be initialized in constructor:
class MyClass {
    OtherClass& m_oc;
    MyClass(OtherClass& oc) : m_oc(oc) {}
};

I think I get it, I still got some errors, but I am going to try it with some very simple code.

Quote from: Hengad
I've heard that even experienced programmers sometimes have problems with pointers.
[...]
PS. Many experienced programmers have said that it's better to write bad but working code, instead of writing nothing
[...]
Some people say that smart pointers shouldn't be used at all
Do you have concrete sources for those claims? What makes you consider those people experienced?

1. This guy was streamer too, he have programmed for 8 years, and he said that he sometimes gets in trouble with pointers, but will eventually still fix the problems.

2. I've read article where this was said, and few streamers (I watch a lot programming live streams) have said to me I should just do something, if I do nothing I won't learn anything, and when you write bad code and you run in trouble you will learn from that what you should not do and what you should.

3. I thought so, but now when you asked about it and I did research, it seems to be false.

No; I don't have anything concrete, this is just what I have heard from different places.

Quote from: GraphicsWhale
Pass a reference or pointer.

I am having trouble with it, but I'm going to try this with something simpler and then try to implement it to my game code.

7
General / Re: Problem with constructors - game development
« on: September 06, 2015, 02:30:45 pm »
Pointers are still language basics. The reason why "experienced" programmers don't know how to use them correctly is that they've skipped some chapters, thinking they wouldn't be important ;)

Probably, + what Satus said.
Quote
But they don't have problems with syntax, only with complicated memory management.

I just want an instance of WindowManager without calling its constructor.
That's not possible. The whole point of constructors is to enforce initialization.

I know that, but there must be something that allows me to use screenDimensions from WindowManager class in World class without calling constructor? I just don't know what.

PS. Many experienced programmers have said that it's better to write bad but working code, instead of writing nothing, so I thought I should even try to make something. :)

That's why they use smart pointers rather than raw pointers.

Some people say that smart pointers shouldn't be used at all, so I haven't even learned about them yet.

Also, as far as I can tell, you want the same WindowManager to be in Core and World, is that right? If it is then both Core and World should have a
Code: [Select]
WindowManager& (which works almost exactly like a normal WindowManager, none of the whole dereferencing stuff).

Thank you, I will try that.

EDIT: Nevermind, I'll just wait for the book, got error:
Quote
In constructor 'Core::Core()':
error: uninitialized reference member 'Core::windowManager' [-fpermissive]

8
General / Re: Problem with constructors - game development
« on: September 06, 2015, 01:49:10 pm »
These are very basic C++ questions that are not related to SFML. If you use a library like SFML, a certain knowledge of the programming language is really required... Otherwise you'll constantly get stuck and waste much more time than learning things correctly in the first place (not just bla bla, I've done the same mistake initially).

I suggest you grab a good C++ book and read it, it will answer your current and future questions :)

I wouldn't say "very basic", I've heard that even experienced programmers sometimes have problems with pointers. But anyways, I have ordered book named "C++ Primer, I guess that is good enough.

I'm confused. Do you know how to pass-by-reference or not? Even if you only know how to use pointers, I'm not sure why you didn't use them.

As I said I have learned only basics; creating a pointer and making it point to some variable. I am not comfortable using them yet.

Using references inside of a class requires the use of an initializer list because references cannot be uninitialized:

Quote
class ClassWithReference
{
    int& x;
public:
    ClassWithReference(int& x_param) : x(x_param) { }
    int& getX() { return x; }
}
 


I don't understand how this helps me in this situation :( I am not passing anything to function, I just want an instance of WindowManager without calling its constructor.

PS: Your use of "cutted" (from your source code) makes me uncomfortable

Sorry, english isn't my native language, and I didn't remember that cut is irregular verb. :)

9
General / Re: Problem with constructors - game development
« on: September 06, 2015, 11:45:18 am »
Is it possible that you've passed the window manager by value instead of by reference or pointer?

Well yes, if you read the code, you see I passed it by value. But I don't know how to pass it by reference. I only know basics of pointers and passing function parameters by reference. I tried to research for it, but I just got errors, could you tell me how do I pass object by reference? (If I understood right, that's what I have to do)

You have two instances of WindowManager in your program and wonder why you have two constructor calls?
Just pass the WindowManager from Core to your world by reference/pointer.

Well I don't "wonder" why. I know why, but I don't know how to prevent this. Check my answer to Hapax.

10
General / Problem with constructors - game development
« on: September 05, 2015, 09:25:38 pm »
I started making platformer game, and I ran into a problem. It is not a big deal, but if I continue developing this game, it will probably become big problem in future (I guess).

I have struggled with this for 3 hours, without success, so I don't really feel like I want to make this code much shorter, I cut out some parts to make it simpler. It is not too long, but I have stuff in separate files so I put source to pastebin.

http://pastebin.com/2QrfRJ1b

More details about the problem:
It compiles all fine, and it draws the tiles exactly I want them to be drawn. I also have messages coming to console about stuff. And when I run the program console looks like this:


It says twice that WindowManager constructor was called and also window options (that windowproperties class i cut out because i didn't see it's necessary, ignore it). Reason behind this is that I call it once in core class (because i need window for game loop) and once in world class (because i need window dimensions to make calculations and stuff for the world). But I don't want that constructor is called twice... I tried to do things things that prevent it from calling 2 times, it succeeded, but then it didn't draw anything to screen? If I continue developing and this twice calling will happen more, it uses a lot of compile time in the end.

So does anyone know what I should do? The main point is that I need screenDimensions from WindowManager, but if I create instance of it, WindowManager constructor will be called twice. If you read all this, you don't even know how much I appreciate it, thank you.

11
General / Re: Help with error, working with classes
« on: September 02, 2015, 07:48:09 pm »
Well yes, I ordered 2 books yesterday, but they haven't arrived yet. I know that is not why inheritance is, but in my snake class I need game class for window to draw the snake, and in game class I need snake to use functions in snake class.. How should I do this?

12
General / Re: Help with error, working with classes
« on: September 02, 2015, 07:24:03 pm »
Yup, I need stuff in Game that is in Snake, and vice versa.

13
General / Help with error, working with classes
« on: September 02, 2015, 06:45:33 pm »
I am doing something wrong here, don't just know what, when compiling it says drawSnake was not declared in this scope. I have just succeeded making pong game, now I am trying to make snake game.

In Game.cpp I call drawSnake like this:
Quote
drawSnake();

Game.h:

Quote
#include <SFML/Graphics.hpp>

#ifndef GAME_H
#define GAME_H

class Game : public Snake
{
    public:
        Game();
};

#endif // GAME_H


In Snake.cpp I have made the drawSnake() function, it doesn't have errors:

Quote
void Snake::drawSnake()
{
    for(int i = 0; i < snake.size(); i++)
    {
        window.draw(snake);
    }
}

Snake.h:

Quote
#include <SFML/Graphics.hpp>
#include <vector>

#ifndef SNAKE_H
#define SNAKE_H

class Snake : public Game
{
    public:
        Snake();
        void drawSnake();
};

#endif // SNAKE_H


Even they are kind of long I tried to shorten them.

14
General / Re: Small questions about game programming
« on: September 02, 2015, 06:35:07 pm »
Thanks @Arcade and @GraphicsWhale for your effort to answer. I understood new things, and your links were helpful too.

15
General / Small questions about game programming
« on: September 01, 2015, 03:25:47 pm »
Some questions about game programming;

1. How should I build my game loop? Or more specificly where? Should I create it to main directly, or should I have class that has function for game loop, and then I just create object and call the function in main? Is there any performance differences between these 2 options?

2. What is best way to create different cursor? Is it just fine to make cursor invisible and draw own cursor to position of mouse? Or is this too heavy thing to handle?

3. How should I implement drawing inventory? Or anything that contains buttons, should I make class that checks for clicks inside specific coordinates or is there better way to do it?

4. How do I know is my code good/efficient? What can I do to improve it?

5. How I should make character dialogues? If there is lot to talk about, it is pain to write that.. Maybe I should use Lua to write the dialogues and then just implement them to characters with c++?

6. Imagine I have created game. I have all textures in folders. Anyone can go and change them? He could take for example wall texture and make it transparent, and with this he sees through walls? Is there a way to precent this? Same with .exe file that runs the game, is it possible to crack the code and edit it?

Here are questions I am wondering about most. I don't expect to get answers to all of them but it would be nice.

Pages: [1] 2