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

Pages: [1] 2
1
General / Re: Lua Integration Affecting Performance
« on: October 20, 2014, 12:31:34 am »
So I did end up profiling the application, and the only difference in performance is a 3% increase in samples with Lua integrated.
3% increase compared to what?

I'm going to try using a Lua wrapper later to see if I can fix the issue that way, but other than that I can't determine what's affecting the performance.
You should find out what function calls take most of the time. Profilers should show you this.
I figured out the problem using a different profiler this time. It turned out it was neither Lua nor my own code affecting the performance. Apparently my solution contained a file that ran a memory leak detection program during runtime that caused the performance spikes whenever and wherever Lua was initialized. I have no idea where that program came from, but removing it from the solution solved the problem entirely.

Thank you all for the help and profiler suggestions!

2
General / Re: Lua Integration Affecting Performance
« on: October 19, 2014, 12:21:13 pm »
I use Visual Studio C++ Express, so I can't really profile without writing some of my own code.
Not true. The profiler doesn't need to be part of your IDE. There are plenty of profilers available that you can use.

A few examples:
Also check out the big List of performance analysis tools at Wikipedia.
So I did end up profiling the application, and the only difference in performance is a 3% increase in samples with Lua integrated. There was also less than 1% change with both the SFML graphics and SFML window. I'm going to try using a Lua wrapper later to see if I can fix the issue that way, but other than that I can't determine what's affecting the performance.

3
General / Re: Lua Integration Affecting Performance
« on: October 19, 2014, 01:54:57 am »
I use Visual Studio C++ Express, so I can't really profile without writing some of my own code. As for wrappers, which library out there do you guys prefer? I didn't intend on including any wrappers at first because technically you don't need any to integrate and run Lua with C++, but now I wouldn't mind to try a few out.

4
General / [Solved] Lua Integration Affecting Performance
« on: October 18, 2014, 09:06:17 am »
Hello all,

So I've been trying to implement Lua with my C++ application. However, initializing a new state for Lua somehow drastically reduces the performance of the application. The frame rate of the render window drops significantly to about 10 to 20 from 60 whenever "luaL_newstate()" is called. My guess is the problem most likely has to do with the garbage collector running between very short intervals, but at this point it's only my best guess.

My code isn't too complicated either, just simple Lua integration.

main.cpp

#include <iostream>
#include <SFML\Graphics.hpp>
#include <Box2D\Box2D.h>
#include "Engine.h"

extern "C" {
# include "lua.h"
# include "lauxlib.h"
# include "lualib.h"
}

lua_State* L;

void main()
{
    L = luaL_newstate();

    sf::RenderWindow _window(sf::VideoMode(sf::VideoMode::getDesktopMode().width, sf::VideoMode::getDesktopMode().height, 32), "Untitled", sf::Style::Fullscreen);
    _window.setFramerateLimit(60);

    b2Vec2 _gravity(0.0f, 60.0f/*9.8f*/);
    b2World *_world = new b2World(_gravity);

    Engine engine;

    while (_window.isOpen())
    {
        sf::Event sfEvent;

        while(_window.pollEvent(sfEvent))
        {
            switch(sfEvent.type)
            {
                case sf::Event::Closed:
                    _window.close();
                    break;
                case sf::Event::KeyPressed:
                    if(sfEvent.key.code==sf::Keyboard::Escape)
                        _window.close();
                    break;
                default:
                    break;
            }
        }

        engine.run(_window, _world);

        delete _world;
        _world = NULL;
    }

    lua_close(L);
    return;
}

Thanks in advance!

5
Graphics / Re: Assigning Texture via For Loop Not Working
« on: June 19, 2013, 12:03:57 pm »
Thanks for all the help, but I've managed to solve this problem using another method. I created a separate loop to define and initialize the collisionArray size.

If any of you want to elaborate more on the copy constructor error I was having, the original post has all of the code definition for the class, and each individual sprite is drawn using the .draw() function in another for loop which takes the size of collisionArray as one of its parameters within the main loop.

Again, thank you all so much for the insight and help!

6
Graphics / Re: Maintaining background image through window.clear()
« on: June 19, 2013, 02:39:50 am »
Have you tried running the code in a loop? Showing us some sample code would really help.

7
Graphics / Re: Assigning Texture via For Loop Not Working
« on: June 19, 2013, 01:08:56 am »
Sorry for restarting this topic, but I don't think I quite understand how copy constructors work in this type of scenario. Applying one automatically returns a runtime error at the point where the sprites are drawn. I know I'm most likely missing something, but I don't know what it is. Otherwise, I probably just have the entire concept wrong at this point.

Header file:

CollisionObject(const CollisionObject &_collisionObject);
CollisionObject &operator= (const CollisionObject &_collisionObject);

C++ file:

CollisionObject::CollisionObject(const CollisionObject &_collisionObject)
{
        collisionObjectString = _collisionObject.collisionObjectString;
        cout << "True" << endl;
}

CollisionObject &CollisionObject::operator= (const CollisionObject &_collisionObject)
{
        if (this == &_collisionObject)
                return *this;

        collisionObjectString = _collisionObject.collisionObjectString;

        return *this;
}

8
Graphics / Re: Assigning Texture via For Loop Not Working
« on: June 17, 2013, 11:02:25 am »
When the collisionArray vector grows, objects are moved in memory, they get new adresses. Which means that all the sprites that were previously pointing to a texture, are now pointing to an invalid address (the texture is no longer there). Therefore, your CollisionObject class should have a copy constructor which correctly assigns the new texture (the copied one) to the copy of the sprite -- otherwise the new sprite will still have a pointer to the old texture which doesn't exist anymore.

Whoops, didn't see your post there Laurent. I don't know/remember how to create copy constructors, so I might as well look up a tutorial to see if I can fix the error.

Thanks for the reply!

9
Graphics / Re: Assigning Texture via For Loop Not Working
« on: June 17, 2013, 10:58:13 am »
I'm starting to get the vibe that this may be an error inside SFML 2.0.
Before blaming SFML, prove that the error is not in your code, by writing a minimal and complete example with only SFML code and no custom functionality.

Sorry, I'd forgotten how to post on these forums ever since my first post requesting for help.

I've attached all the files that are required, including images, to replicate the error in a .rar file. All you need to do is copy it into a main project directory and run main.cpp. I've compressed the project to its bare minimum so that it only replicates the error.

10
Graphics / Re: Assigning Texture via For Loop Not Working
« on: June 17, 2013, 05:24:31 am »
I'm starting to get the vibe that this may be an error inside SFML 2.0. Maybe one of the admins should take a look at the source code of the graphics library?

11
Graphics / Re: Assigning Texture via For Loop Not Working
« on: June 15, 2013, 09:09:11 pm »
Correct, collisionArray is defined using a CollisionObject class, though it doesn't use pointers as far as I can tell. The only function in that class as of now is the one I posted in the original post, initCollisionObject. The constructor of that class defines only the width, height, x, and y positions of the sprite used in that class.

How collisionArray is defined in the header file:

#ifndef Engine_h
#define Engine_h

#include <iostream>
#include <SFML\Graphics.hpp>
#include <Box2D\Box2D.h>
#include "pugixml.hpp"
#include "Collision.h"
#include "CollisionObject.h"
#include "Player.h"
#include "Enemy.h"
#include "Lighting.h"

using namespace std;
using namespace sf;
using namespace pugi;

class Engine
{
public:
        Engine();
        ~Engine();
        void init(sf::RenderWindow &_window, b2World &_world);
        void run(sf::RenderWindow &_window, b2World &_world);
        void keyEvents(sf::RenderWindow &_window);
        void physics(sf::RenderWindow &_window, sf::RenderTexture& _texture, b2World &_world);
        void rayCast(sf::RenderWindow& _window, b2World* _world);

private:
        Collision collision;
        CollisionObject collisionObject;
        Player player;
        Enemy enemy;
        Lighting lighting;

        vector<CollisionObject> collisionArray;
        int currentCollisionObjectIndex;

        int cameraX;
        int cameraY;

        float closestFraction;
        b2Vec2 p1;
        b2Vec2 p2;
        b2Vec2 intersectionPoint;

        xml_document doc;
};

#endif

12
Graphics / Re: Assigning Texture via For Loop Not Working
« on: June 15, 2013, 10:46:05 am »
I should also point out that if I initialize every element of the vector array individually outside of the for loop, everything appears as it should. However, as soon as I initialize them via the for loop, every sprite except for the last one in the vector array has their texture rendered null.

13
Graphics / Re: Assigning Texture via For Loop Not Working
« on: June 14, 2013, 11:36:34 pm »
Edit: Fixed a small syntax error accidentally copied over from the code, but the program still stands as it is and is still not working.

14
Graphics / Assigning Texture via For Loop Not Working
« on: June 14, 2013, 06:49:34 am »
For the past week I've been trying to assign specific textures to sprites in a vector array via a for loop, with both elements being called from a XML file using PugiXML. With my current code, every sprite except for the last one within the vector array appears to have a white texture incorrectly assigned to it, with only the last one within the vector array having the correct texture assigned to it.

So far, I don't see any flaws within my code, which is confusing me. If anyone happens to see an error that I don't, a reply would be greatly appreciated.

initCollisionObject Function:

void CollisionObject::initCollisionObject(std::string fileName, b2World &_world, float objectX, float objectY, float objectRotation)
{
        collisionObjectString = fileName;
        collisionObjectImage.loadFromFile(collisionObjectString);
        collisionObjectTexture.loadFromImage(collisionObjectImage);
        collisionObjectSprite.setTexture(collisionObjectTexture);
        width = collisionObjectSprite.getGlobalBounds().width;
        height = collisionObjectSprite.getGlobalBounds().height;
        x = objectX;
        y = objectY;
        rotation = objectRotation;
        collisionObjectSprite.setOrigin(collisionObjectSprite.getGlobalBounds().width / 2, collisionObjectSprite.getGlobalBounds().height / 2);
        collisionObjectSprite.setPosition(x, y);
        collisionObjectSprite.setRotation(rotation);

        createStaticCollision(_world, x, y, width, height, rotation);

        return;
}

for Loop:

for (xml_node collisions = doc.child("level").child("collisions").child("object"); collisions; collisions = collisions.next_sibling("object"))
{
        //cout << "Iterated" << endl;
        xml_attribute textureAttribute = collisions.attribute("spritesheet");
        xml_attribute xPosAttribute = collisions.attribute("x");
        xml_attribute yPosAttribute = collisions.attribute("y");
        xml_attribute rotationAttribute = collisions.attribute("rotation");
       
        string texture = textureAttribute.as_string();
        int xPos = xPosAttribute.as_int();
        int yPos = yPosAttribute.as_int();
        int rotation = rotationAttribute.as_int();
        collisionArray.push_back(collisionObject);
        collisionArray[currentCollisionObjectIndex].initCollisionObject(texture, _world, xPos, yPos, rotation);

        currentCollisionObjectIndex++;
}

15
General / Re: SFML 2.0 Shader Masking
« on: December 06, 2012, 06:21:41 pm »
Yes! This is EXACTLY what I was going for!

Well, if it's EXACTLY what you're going for, I applied a little gaussian blur to your light.png to soften the rays up in the image

Looking at your code, I assume you used an image manipulation program rather than a shader to apply your Gaussian blur?

Pages: [1] 2
anything