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

Pages: [1]
1
Network / Basic Threaded Server?
« on: September 06, 2009, 08:23:02 pm »
Hey can anyone give me some pointers on how to go about making a threaded server with C++ / SFML? I made one in Ruby a loong time ago and I'm kindof stuck I'm not sure what to do.

Hell, even if someone could write a basic server code for me that'd be good (listens, starts new thread for each client)

Or even write a tutorial on how to do it for the Tutorials section of the site ^^

When I do get this all figured out I'll write a tutorial here unless someone else does.

2
Window / Fullscreen Stopped Stretching?
« on: September 03, 2009, 05:27:22 am »
So yeah I was programming my code and everything was going well.

I was rendering a 800x600 fullscreen window which would go full-screen and stretched out to fit my widescreen laptop (with a 1024x600 resolution normally.)

However, after adding a few libraries and a lot more code and moving things around, it STOPPED stretching. Now it goes fullscreen and draws 800x600 in the CENTER of the screen instead of stretching to fit the whole screen.

Any ideas how to fix this? Thanks!

Here's my code. (getting long)

Code: [Select]


////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/Audio.hpp>
#include "cpGUI.h"

using namespace std;

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////


// Functions For Different Screens
int ShowLoginScreen();
int ShowGameScreen();




// Global Variables
string CurrentGameScreen = "LoginScreen";
string g_username;


// Define 'App'
sf::RenderWindow App;

int main()
{
// Render The Window
App.Create(sf::VideoMode(800, 600, 32), "Wonderful Game", sf::Style::Fullscreen);
    // Get a reference to the input manager associated to our window, and store it for later use
    const sf::Input& Input = App.GetInput();

    // Start main loop
    while (App.IsOpened())
    {
if (CurrentGameScreen == "LoginScreen")
{
ShowLoginScreen();
}
if (CurrentGameScreen == "GameScreen")
{
App.ShowMouseCursor(false);
ShowGameScreen();
}

if (CurrentGameScreen == "Exit")
{
App.Close();
}

    }

    return EXIT_SUCCESS;

}


///////////////////////////////////////
///////////////////////////////////////
//////ShowLoginScreen Function
///////////////////////////////////////
///////////////////////////////////////


int ShowLoginScreen()
{

// Load Variables
int LoginScreenIsLoaded = 0;
string username;
string password;
int rememberMe = 0;

// Load Images
sf::Image LoginBackImg;
if(!LoginBackImg.LoadFromFile("img/LoginBack.png"))
//ERROR
LoginBackImg.SetSmooth(false);

sf::Sprite LoginBack(LoginBackImg);
LoginBack.SetPosition(0.f, 0.f);

// Start Main Game Screen Loop
LoginScreenIsLoaded = 1;

while (LoginScreenIsLoaded == 1)
{

        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
{
CurrentGameScreen = "Exit";
LoginScreenIsLoaded = 0;
}

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
CurrentGameScreen = "Exit";
LoginScreenIsLoaded = 0;
}
}


// Get elapsed time
float ElapsedTime = App.GetFrameTime();





//Clear Screen
App.Clear();

// Draw LoginBack
App.Draw(LoginBack);

// Display Window On Screen
App.Display();
}
}






///////////////////////////////////////
///////////////////////////////////////
//////ShowGameScreen Function
///////////////////////////////////////
///////////////////////////////////////

int ShowGameScreen()
{

//Load Variables
int CurrentFrame = 1;
int FrameWidth = 50;
int FrameHeight = 80;
int CharSubRectY1 = 0;
int CharSubRectY2 = FrameHeight;
int CharIsWalking = 0;
int isAnimating = 0;
float FPS;
float CurrentFPS;
int TotalFrames;
int GameScreenIsLoaded = 0;

// Load Images
sf::Image MaleBaseSheet;
if(!MaleBaseSheet.LoadFromFile("img/MaleBaseSheet.png"))
//ERROR
MaleBaseSheet.SetSmooth(false);

sf::Sprite MaleBase(MaleBaseSheet);
MaleBase.SetPosition(300.f, 200.f);

// Start Main Game Screen Loop
GameScreenIsLoaded = 1;


while (GameScreenIsLoaded == 1)
{


        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
{
CurrentGameScreen = "Exit";
GameScreenIsLoaded = 0;
}

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
{
CurrentGameScreen = "Exit";
GameScreenIsLoaded = 0;
}
}


// Get elapsed time
float ElapsedTime = App.GetFrameTime();



// Movement
CharIsWalking = 0;
if (App.GetInput().IsKeyDown(sf::Key::Left))
{
CharIsWalking = 1;
MaleBase.Move(-80 * ElapsedTime, 0);
CharSubRectY1 = 80;
CharSubRectY2 = 160;
}
if (App.GetInput().IsKeyDown(sf::Key::Right))
{
CharIsWalking = 1;
MaleBase.Move( 80 * ElapsedTime, 0);
CharSubRectY1 = 160;
CharSubRectY2 = 240;
}
if (App.GetInput().IsKeyDown(sf::Key::Up))
{
CharIsWalking = 1;
MaleBase.Move(0, -80 * ElapsedTime);
CharSubRectY1 = 240;
CharSubRectY2 = 320;
}
if (App.GetInput().IsKeyDown(sf::Key::Down))
{
CharIsWalking = 1;
MaleBase.Move(0,  80 * ElapsedTime);
CharSubRectY1 = 0;
CharSubRectY2 = 80;
}


if (CharIsWalking == 1)
{
if(isAnimating == 0)
{

FPS = 3;
TotalFrames = 4;
CurrentFPS = FPS;
isAnimating = 1;
}

if(isAnimating == 1)
{
CurrentFPS = CurrentFPS - 10 * ElapsedTime;
if(CurrentFPS < 1)
{
if(CurrentFrame < TotalFrames)
{
CurrentFrame = CurrentFrame + 1;
}
else
{
CurrentFrame = 1;
}

isAnimating = 0;
}
}
}

else
{
CurrentFrame = 1;
}


//Set Sub Rect
MaleBase.SetSubRect(sf::IntRect(CurrentFrame * FrameWidth - FrameWidth, CharSubRectY1, CurrentFrame * FrameWidth, CharSubRectY2));

//Clear Screen
App.Clear();

// Draw MaleBase
App.Draw(MaleBase);

// Display Window On Screen
App.Display();



}

}



3
Graphics / FPS to Graphical Font?
« on: August 30, 2009, 04:57:59 am »
Hi I know this probably seems newb but I've been searching and fooling around but what I'm trying to do is get my app to write the Frame Rate to the top right of the string like "FPS: #" using sf::string.

Is there any way to get the FPS and convert it to an sf::string to write it like this or another way to do it? Thanks.

4
System / Error Message Box?
« on: August 27, 2009, 06:52:29 am »
Hi I was wondering if there was any way to make an Error Message Box pop up? Similar to this...



But with a custom message.

5
Window / Program Hangs On Exit
« on: August 27, 2009, 06:49:55 am »
Okay first off, HOLY COW THAT WAS THE HARDEST ANTI BOT REGISTRATION THING I'VE EVER DONE.

Secondly, the real issue.

Anyways, I'm new to SFML, and LOVING IT SO MUCH so far. There's just one teency weency problem...

Well, when I debug my solution, everything runs fine. However when I hit the Esc key it exits but doesn't stop debugging. After about 1-2 minutes I will get a debug line saying that the program returned 0. And then it's done debugging. For debugging this isn't a problem because I can hit "stop debugging" to make it end immediately when I'm done.

But the big issue is that when I run the 'Release' exe file, it does the same thing. The process Window 2.exe is open for 1-2 minutes after I exit. I could just end process but I mean, seriously? The process should end itself when the program is exited.

Anyways, here's my code. Help me out ^^ Thanks!

Code: [Select]



////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>


////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Wonderful Game");

    // Get a reference to the input manager associated to our window, and store it for later use
    const sf::Input& Input = App.GetInput();

sf::Image MaleBaseSheet;
if(!MaleBaseSheet.LoadFromFile("sprite/MaleBaseSheet.png"))
return EXIT_FAILURE;

sf::Sprite MaleBase(MaleBaseSheet);
MaleBase.SetSubRect(sf::IntRect(0, 0, 50, 80));
MaleBase.SetPosition(500.f, 500.f);




    // Start main loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();

            // Escape key : exit
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }


//Clear Screen
App.Clear();

        // Display window on screen
App.Draw(MaleBase);

        App.Display();
    }

    return EXIT_SUCCESS;
}




Well when I hit exit it correctly executes App.Close() and the window closes. The issue is that the process continues to run after the "return EXIT_SUCCESS" is executed and doesn't completely shut down for about 1-2 minutes. Any fix? This is probably going to be pretty important down the line...

Thanks!

Pages: [1]