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

Author Topic: porting the tutorial game engine over to linux....  (Read 3330 times)

0 Members and 1 Guest are viewing this topic.

pixel_pusher

  • Newbie
  • *
  • Posts: 6
    • View Profile
porting the tutorial game engine over to linux....
« on: September 01, 2010, 10:57:09 pm »
Hi, I just started messing around with SFML, and for the heck of it, I'm working on the game engine from the tutorials page. Mainly, I'm just trying to replace the win32 function calls with more cross-platform stuff, so I can play with this thing on Linux.

What's giving me trouble right now is the use of _snprintf_s, lines from IState.hpp in the Draw() method:

Code: [Select]

char frames[20];
....
_snprintf_s(frames, 20, 20, "FPS: %4.2f", (float)mFrames / mFrameClock.GetElapsedTime());




Yeah, im embarrassed, I don't know my c library..... is there a quick replacement func that does the same thing? I know there's a function for this somewhere, but offhand all I can think of is printf and its variants, which wont do the trick AFAIK.
Any suggestions?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
porting the tutorial game engine over to linux....
« Reply #1 on: September 01, 2010, 11:02:37 pm »
What about true C++, like std::string and std::ostringstream?
Laurent Gomila - SFML developer

pixel_pusher

  • Newbie
  • *
  • Posts: 6
    • View Profile
porting the tutorial game engine over to linux....
« Reply #2 on: September 02, 2010, 09:59:38 pm »
Quote
What about true C++, like std::string and std::ostringstream?


Well,  I was shooting for as small of a change as possible... just while I get up and running.  sprintf seems to work as a quick-fix, for now.

But, if I were to use string and osstream, wouldn't that be a little costly inside of update and render methods? I'd think I'd at least need to restructure the logging so that I wasn't calling these constructors twice every frame.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
porting the tutorial game engine over to linux....
« Reply #3 on: September 03, 2010, 01:50:21 am »
Quote from: "pixel_pusher"
But, if I were to use string and osstream, wouldn't that be a little costly inside of update and render methods? I'd think I'd at least need to restructure the logging so that I wasn't calling these constructors twice every frame.
If you really have performance problems, measure the required time and/or use a profiler. The stream operations probably become negligible, as soon as your game logic or graphic gets more complex.

Choosing a bad design based on speed assumptions (not facts) is also called premature optimization. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

fixus971

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
    • http://www.fixweb.it
GQE on Linux (Ubuntu) NetBeans G++
« Reply #4 on: January 26, 2011, 01:28:44 am »
Hi. I converted and run GQE on Linux with NetBeans/G++
char updates[20];     -->  std::ostringstream updates;
_snprintf_s(updates.. -->  updates << "UPS: " << std::fixed ..

in IState.hpp:
Code: [Select]

    /**
     * Update is responsible for handling all State update needs for this
     * State when it is the active State.
     */
    virtual void Update(void) {
      //char updates[20];
 std::ostringstream updates;
 
      // Check our App pointer
      assert(NULL != mApp && "IState::Update() bad app pointer");
 
      // Increment our update counter
      mUpdates++;
      if(mUpdateClock.GetElapsedTime() > 1.0f)
      {
        // Update our UPS string to be displayed
        //_snprintf_s(updates, 20, 20, "UPS: %4.2f", (float)mUpdates / mUpdateClock.GetElapsedTime());
        updates << "UPS: " << std::fixed << std::setprecision(2) << std::setw(7)
<< (float)mUpdates / mUpdateClock.GetElapsedTime();
        mUPS.SetText(updates.str());
 
        // Reset our Update clock and update counter
        mUpdates = 0;
        mUpdateClock.Reset();
      }
    };
 
    /**
     * Draw is responsible for handling all Drawing needs for this State
     * when it is the Active State.
     */
    virtual void Draw(void) {
      //char frames[20];
   std::ostringstream frames;

      // Check our mApp pointer
      assert(NULL != mApp && "IState::Draw() invalid app pointer provided");
 
 
      // Increment our frame counter
      mFrames++;
      if(mFrameClock.GetElapsedTime() > 1.0f)
      {
        // Get our FramesPerSecond value
        //_snprintf_s(frames, 20, 20, "FPS: %4.2f", (float)mFrames / mFrameClock.GetElapsedTime());
        //mFPS.SetString(frames);
        frames << "FPS: " << std::fixed << std::setprecision(2) << std::setw(7)
<< (float)mFrames / mFrameClock.GetElapsedTime();
        mFPS.SetText(frames.str());
 
        // Reset our Frames clock and frame counter
        mFrames = 0;
        mFrameClock.Reset();
      }
 
      // Draw the Frames Per Second debug value on the screen
      mApp->mWindow.Draw(mFPS);
 
      // Draw the Updates Per Second debug value on the screen
      mApp->mWindow.Draw(mUPS);
    };
^_^=>Il calcolatore รจ straordinariamente veloce, accurato e stupido. Gli uomini sono incredibilmente lenti, imprecisi e creativi. L'insieme dei due costituisce una forza incalcolabile. (Albert Einstein)

 

anything