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

Pages: [1] 2
1
General / Re: SFML 2.5 CMake Migration
« on: July 18, 2018, 03:14:05 pm »
1. I definitely agree with OvermindDL1 in the fact that you should have use namespaced targets to go "all the way" with the modernization.

2. (This is a bit of a nitpicking) Assuming that SFML follows something like Semantic Versioning for its own versions (where major changes represent overhauls, minor changes are for additions WITHOUT BREAKING backwards compatibility, patch changes are for bugfixes, etc.), doesn't including this CMake change in a minor version break backwards compatibility? Now it seems that someone using CMake cannot simply (reasonably) try and update their code to use SFML 2.5 (Assuming they don't use the older FindSFML.cmake, which might not be compatible anymore due to the somewhat different folder structure, although I haven't tested this to make sure) without having to deal with changing the CMake code a little bit. Now obviously, this isn't a major problem, but TBH, I would have preferred a breaking change such as this one to be implemented in SFML 3.0, because then an overhaul of everything is logical.

2
Hmmmm, I'll definitely make a point to look at your library for larger games, but the game I'm currently making doesn't really need it. However, I will take a look at the source code you used to see how you implemented a fixed timestep. Thanks for linking!

3
I actually don't see the "compromise" you are referring to in the article. Are you talking about something similar to the deWiTTERS game loop? (Thanks for telling me how to embed links, BTW).

I don't see any sort of compromise in the code I copied and pasted from Github either, but I still want to avoid the 30 second problem you mentioned (although I presume interpolation should fix the problem).

Could you provide some example code to illustrate your point (I find that I understand that better than just words  ::)?

4
General / If statement vs While loop for Updates in a Fixed Timestep
« on: July 14, 2018, 01:18:31 am »
Let's say I'm in the process of implementing the game loop for my SFML game. In order to maintain a fixed timestep, I would follow something like outline in: https://gafferongames.com/post/fix_your_timestep/

In order to implement something like that, the code would probably be:

void Game::run()
{
        sf::Clock clock;
        sf::Time timeSinceLastUpdate = sf::Time::Zero;
        while (mWindow.isOpen())
        {
                sf::Time elapsedTime = clock.restart();
                timeSinceLastUpdate += elapsedTime;
                while (timeSinceLastUpdate > TimePerFrame)
                {
                        timeSinceLastUpdate -= TimePerFrame;

                        processEvents();
                        update(TimePerFrame);
                }

                updateStatistics(elapsedTime);
                render();
        }
}
 

(This is directly copied and pasted from https://github.com/SFML/SFML-Game-Development-Book/blob/master/01_Intro/Source/Game.cpp, and seems to be the direct implementation of the concept linked to in the article above).

However, I recently bought the book SFML Game Development By Example (by Raimondas Pupius), and found the following paragraph in Chapter 2:

Quote
... (Page 32)
Unlike the variable time-step, where the next update and draw happens as soon as the previous one is done, the fixed time-step approach will ensure that certain game logic is only happening at a provided rate. It's fairly simple to implement a fixed time-step. First, we must make sure that instead of overwriting the elapsed time value of the previous iteration, we add to it like so:

void Game::RestartClock() {
    m_elapsed += m_clock.restart();
}

The basic expression for calculating the amount of time for an individual update throughout a 1 second interval is illustrated here:

                           1.0f
FrameTime =  --------------
                       Updates/s

(It's actually an image, but whatever)

Let's say we want our game to update 60 times a second. To find the frame time, we would divide 1 by 60 and check if the elapsed time has exceeded that value, as shown here:

float frametime = 1.0f / 60.0f;

if (m_elapsed.asSeconds() >= frametime) {
    // Do something 60 times a second.

    m_elapsed -= sf::seconds(frametime);
}

As evident, the difference between both snippets is that one uses a while loop to check if the elapsed time is greater than the frametime, and keeps updating/subtracting until it isn't. This seems logical to me. The other approach, as shown in the quote, suggests to skip updates (to increase the elapsed time) until the time comes. These to me seem completely different ways of implementing a similar concept. Which type of fixed timestep should I use?

(Side question: How do I embed a link with its own text i.e in markdown: [link text](URL)?)

5
General discussions / Re: How do Games Manage Resource Files?
« on: July 09, 2018, 02:45:48 pm »
Sorry, this must be me being naive, but I _still_ don't understand how this works. I can't even find the definition for DirectoryResourceProvider. Daid, is it possible you could provide me with a minimal CMake script that configures RESOURCE_BASE_DIR like for your project?

6
General discussions / Re: How do Games Manage Resource Files?
« on: July 06, 2018, 01:43:43 am »
@Daid, that is somewhat helpful, but I'm still lost on how to set RESOURCE_BASE_DIR. I was looking in your CMakeLists.txt, and I see this:

Code: [Select]
# install resources, scripts, and packs to app bundle instead of system dir.
if(APPLE)
set(CMAKE_INSTALL_PREFIX "./")
elseif(UNIX)
# Set RESOURCE_BASE_DIR on Unix so the built binary is able to find resources
add_definitions(-DRESOURCE_BASE_DIR="${CMAKE_INSTALL_PREFIX}/share/emptyepsilon/")
endif()

Now this seems fine at first glance, but I don't think this would work.
Suppose I had an source directory with a CMake file, and I did mkdir build, cd build, and cmake .. on a unix system (A basic out-of-source build). And now I wanted to run this app. However, since the RESOURCE_BASE_DIR is set to /usr/share/emptyepsilon, the game is going to look for resources there, when they aren't there in the first place. How owuld that work?

7
General discussions / Re: How do Games Manage Resource Files?
« on: July 05, 2018, 02:36:13 pm »
Thanks for the reply, but unfortunately I still don't have a complete understanding of how this works.... ;(


I did some research, and found this: https://askubuntu.com/a/27257
I guess that answers the question about where these things are stored on Linux.

But a question still remains: How does an application "configure" the ResourcePath, as you mentioned?

Also, on another side note: I've installed various high-end games on my PC before. I've gone into C:\Program Files\Application before. How come I don't see hundreds of sprites and sound files and script files in these directories? I doubt these games don't need external files, but they must be stored _somewhere_, right? So, how do video games specifically manage their resource files?


8
General discussions / How do Games Manage Resource Files?
« on: July 05, 2018, 01:14:13 am »
TBH, this question doesn't necessarily to SFML specifically, but to any program that requires a resource file.

Say I have a game, compiled into a program game.exe. Said game has a line in its code:

std::ifstream ifs{ "important_data.lua" };

Now obviously, in order for the game to work, this executable needs the resource file important_data.lua in the same directory as the executable. This is quite easy to manage on Windows and MacOSX, where applications are bundled so that they have a folder dedicated to their own applications. (C:\Program Files\program_name\... and on OSX executable/Contents/...). However, I don't understand how this works on Linux. Now obviously, the executable gets installed to /usr/local/bin or /usr/bin. Now where does the resource file go? Would it go to bin, where any other application in the directory has access to it, or somewhere else? I would think it would go /usr/share, but then the application wouldn't run because ifstream would be unable to access it. Where should this resource file be placed for my game?

If It's relevant, I'm using CMake to manage everything related to my game.

9
General / Re: SFML+CLION +CMAKE (Windows10) configuration
« on: August 13, 2017, 06:57:33 pm »
Correct me if I am wrong, but you do not need to link the dependencies unless you are linking SFML statically, which you are not.

10
Ok, thanks for the reply, Ill be sure to try that out.

11
General / Absolutely Confused with CMake in finding SFML include files
« on: August 12, 2017, 10:23:53 pm »
I was trying to configure CMake to link the SFML libraries on my Windows computer, and am failing miserably.

My directory looks as follows

Code: [Select]
   |-build
      |__//Build stuff
   |-cmake_modules
     |__FindSFML.cmake
   |-main.cpp
   |-CmakeLists.txt

For some reason, while CMake is able to find SFML, it is unable to find the include directory of it. I run CMake as follows:

Code: [Select]
cmake .. -DCMAKE_PREFIX_PATH=C:/SFML-2.4.2

and my CMakeLists.txt looks as follows:

Code: [Select]
cmake_minimum_required(VERSION 3.9)
project(SFML-CmakeTest)

set(CMAKE_BUILD_TYPE Release)

set(EXECUTABLE_NAME "sfml_test_cmake")

add_executable(${EXECUTABLE_NAME} main.cpp)

set(SFML_FIND_PATH ${CMAKE_PREFIX_PATH})
set(SFML_INCLUDE_PATH "${SFML_FIND_PATH}/include")

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2.4 REQUIRED system window graphics network audio)
include_directories(${SFML_INCUDE_PATH})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})

my main.cpp is as simple as it gets:

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow testWindow{ sf::VideoMode{ 640, 480 }, "Test Window", sf::Style::Default };

while (testWindow.isOpen())
{
sf::Event winEvent;
while (testWindow.pollEvent(winEvent))
{
if (winEvent.type == sf::Event::Closed)
{
testWindow.close();
}
}
testWindow.clear();
testWindow.display();
}
}

Unfortunately, I get the VS error, unable to find SFML/Graphics.hpp. What am I doing wrong? My SFML is located in C:\SFML-2.4.2

12
SFML projects / Re: Just another Snake clone
« on: August 11, 2017, 12:09:07 am »
Thanks again!

Quote
Doing @ at people doesn't notify them in any way.

Lol, I'm new to this forum and all, soooo

Ill be sure to read that article and I now understand what you mean with the
Code: [Select]
unique_ptr
I agree, I should probably do that with the food, I hate code repetition in general and care more to readability than to performance, (unless necessary of course).

I'll be sure to do what you said with the
Code: [Select]
Direction class.

Quote
It doesn't affect the compilation and you can also put two semicolons at end of each line of code but no one does that. You can also make inline member functions multi line or put them under the class to not have them mixed with members.

Point taken. Just because I can doesn't mean I should...

As for the
Code: [Select]
GameState thing, I see what you mean with the boolean flag. Sure, I will do that in the future.

Thanks!

13
SFML projects / Re: Just another Snake clone
« on: August 10, 2017, 05:31:23 pm »
First of all, thanks for the review!

Quote
there is few news but their results instantly go into a unique_ptr so it's okay (maybe it could move unique_ptr into there instead but that's stretching it and making the interface a bit less clear),

Sorry, I don't understand what that means, so could you be a little clearer?

Quote
You probably should put resources like fonts and images in separate folder called 'read' or 'data' or something, not in src where code is.

Yea, I probably would do that for larger games with loads of resources. Since this was small, I decided to keep it all in the same place.

Quote
You use {} (the new list stlye initialization, etc.), it has upsides about safety and so on but it looks so weird and out of place when used so often and even sf::Vector2f(1.f, 1.f) is written with {} instead and you pad it with spaces too so it looks extra strange.

The spaces are Visual Studio formatting, so I just keep it :P, As for the braces, its just my style, and I personally like it so it separates functions from classes and aggregates.

Quote
You don't need to use WinMain, etc. you can just use normal mail and link to sfml-main. You also use MessageBox which makes it not portable but it's just this one place.

Noted.

Quote
The Direction class is a bit weird. I'd use an enum (or a strong C++11 enum if you prefer them) and then use free functions for reverse and vector from direction.

That was what I initially did, but I wanted to reduce the amount of switch statements in my Snake class.

Quote
You don't need the vector2Cast function because sf::Vector2f can take other kinds of sf::Vector and does the same (without the exception throwing/check).

Just wanted to turn off warnings in VS. :P I get a niggling feeling seeing one.

Quote
You put private members without a specifier in the class while it's a bit of a custom/readability aid to put public members first and private ones second, take a look at SFML.

Thats something I might consider, although it is more of a style thing.

Quote
You put a semicolon after inline method body which isn't needed, like that (the final semicolon isn't needed): inline void doStateChangeDelay() const override { sf::sleep(sf::milliseconds(750)); };

Preference and consistency with members; unless it is wrong, it shouldn't matter

Quote
Naming base State class GameState is a bit. For a moment I thought I'm missing the cpp until I found out SnakeGame is the class that inherits from it.

Noted, probably will use new name like BaseState to clarity

Quote
If you want you can put u after a number to signify it's unsigned, like: const sf::Vector2u windowSize_{ 400u, 336u };

Huh, I did that in other parts of my code. How did I miss that?

Quote
You might want to check the image is the size you expect before calling setIcon with it, this can crash your game even if the image is too small (unlikely) or cause visual glitches (more likely).

Speaking of that image, windowIcon.png is PNG image data, 2880 x 1800, 1-bit colormap, non-interlaced not a 16x16 icon of any kind. Why is that so?

That was just a quick image that I expected to be cropped on its own. As for the checking, I didn't know that, so thanks!

Quote
That function from SnakeGameApp could be const: inline std::unique_ptr<GameState> getInitialState() { return std::make_unique<MainMenu>(windowSize_); };

Noted

Quote
You might look into making logic independent from graphics/framerate (for future projects, not here where it doesn't matter).

clarify?

Quote
Why in GameState is nextState_ initialized to this and no just NULL, 0x0 or nullptr (whichever you prefer)?

If I set it to nullptr, it would mean the game is over and the state shouldn't be changed in the next frame and the window should instead close. I made it this, so that it shows that the state stays the same.

Anyways, thanks for your review, and please answer my questions @FRex

14
SFML projects / Re: Just another Snake clone
« on: August 09, 2017, 07:59:00 pm »
@FRex did you look at my code yet?

15
SFML projects / Re: Just another Snake clone
« on: August 08, 2017, 06:10:59 pm »
Ok, Thanks for the detailed answer!

So here is my final verdict:

Just make a x86 version of the game, unless I am making a memory heavy, performance needing game. Would this be a good rule to follow?

As for my code, feel free to review the overall content of my code and post code review here. Thanks!  :D

Pages: [1] 2
anything