Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:39:48+00:00 2026-05-27T11:39:48+00:00

For a school project I need to (re)create a fully functional multi-player version of

  • 0

For a school project I need to (re)create a fully functional multi-player version of R-Type without the use of the following external libraries:

  • Boost
  • SFML/SDL
  • Qt
  • Use of C++11 not allowed

Moreover, this game must be fully portable between Fedora(Linux) and Windows. I am in charge of the server so the use of any graphic libraries is strictly prohibited.

In order to create a correct game loop I need a correct Timer class, similar as those found in the SDL which implements GetTicks() or GetElapsedTime() methods. But I asked myself what would be the best way to create such a Class, so far this is how I would start:

  • Creating a threaded-class using pthread(which is portable)
  • Using the functions time() and difftime() in a loop to determine how much time was elapsed since the last tick.

Knowing that this class will be used by dozens of instances playing at the same time, should I use the Singleton Design Pattern? Will this methods be accurate?

EDIT: Changed the explanation of my question to fit more my needs and to be more accurate on what I am allowed to use or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:39:48+00:00Added an answer on May 27, 2026 at 11:39 am

    There’s not an easy way to do what you’re thinking. Luckily, there are easy ways to do what you want.

    First: Using the functions time() and difftime() in a loop to determine how much time was elapsed That’s a terrible idea. That will use 100% of one of your CPUs and thus slow your program to a crawl. If you want to wait a specific amount of time (a “tick” of 1/60 of a second, or 1/10 of a second), then just wait. Don’t spin a thread.

    header:

    long long get_time();
    long long get_freq();
    void wait_for(long long nanoseconds);
    

    cpp:

    #ifdef _MSC_VER //windows compiler for windows machines
    long long get_time() {
        LARGE_INTEGER r;
        QueryPerformanceCounter(r);
        return r.QuadPart;
    }
    long long get_freq() {
        LARGE_INTEGER r;
        QueryPerformanceFrequency(r);
        return r.QuadPart;
    }
    void wait_for(long long nanoseconds)
    {
        Sleep(nanoseconds / 1000000);
    }
    #endif
    #ifdef __GNUC__ //linux compiler for linux machines
    long long get_time() {
        timespec r
        clock_gettime(CLOCK_MONOTONIC, &r);
        return long long(r.seconds)*1000000000 + r.nanoseconds;
    }
    long long get_freq() {
        timespec r
        clock_getres(CLOCK_MONOTONIC, &r);
        return r.nanoseconds;
    }
    void wait_for(long long nanoseconds)
    {
        timespec r = {nanoseconds/1000000000, nanoseconds%1000000000};
        nanosleep(&r, NULL);
    }
    #endif
    

    None of this is perfect (especially since I don’t code for linux), but this is the general concept whenever you have to deal with the OS (since it isn’t in the standard and you cant use libraries). The Windows and GCC implementations can be in separate files if you like

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a school project I need to create a program and it'd be nice
For a school project, I need to create a way to create personnalized queries
For a school project i need to write or use a online programming editor.
I need to create a query with multiple tables for a project for school,
I need to write a Linux shell for a school project. We can use
For a school project, we need to create a fairly simple app using C++
I'm currently building a console app for a school project and I really need
for a school project I need to find theta and phi for a spherical
I need to build a small database for a school project and I'd like
First of all, I'll admit this is a school project, so I need more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.