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.


Topics - arnavb

Pages: [1]
1
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)?)

2
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.

3
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

4
SFML projects / Just another Snake clone
« on: August 07, 2017, 12:49:51 am »
Hey guys, I recently started using SFML, and made a clone of the classic game Snake! I am really enjoying usage of the library, and plan on making more games with it. Anyways, I want to get feedback on my app (other than my questionable font and color choices ;P), and there are links to its download (sadly only for Windows (x64/x86)) below. Any and all feedback is appreciated. Thanks!

Links to .zip files (Just run the application in the folder)

Windows (x64): https://drive.google.com/file/d/0B5LejbIN6T8gUGJXNFotZ0dJZTA/view?usp=sharing
Windows (x86): https://drive.google.com/file/d/0B5LejbIN6T8gVmNBNXFJSHl1ckU/view?usp=sharing

Thanks Again!!

A screenshot is attached

Pages: [1]
anything