• What do you need help with? Version 1
    5,001 replies, posted
I don't think you should be creating an entity that inherits from a shape. Just make the shape a member.
[QUOTE=shill le 2nd;25964740]I don't think you should be creating an entity that inherits from a shape. Just make the shape a member.[/QUOTE] Do you mean a friend?
[QUOTE=Richy19;25962759]Its giving me errors: Circle is not a member of sf::Shape Circle base class undefined sf is not a class or namespace circle base class undefined [/QUOTE] AFAIK sf::Shape::Circle should be a function to create sf::Shape. You can't inherit a function.
[QUOTE=Richy19;25964927]Do you mean a friend?[/QUOTE] No, he means a member. i.e, a member object of your class.
Does anyone know of any good explanations or reviews of the Quake engines (In particular Quake 1 and 2) at a source level?, The only one I found was a small 3 parter on Quake 3 that didn't really explain very much at all.
Ughhh whats up with this now? [img]http://img530.imageshack.us/img530/9777/25620676.png[/img] The text isnt showing up right, the FPS are stupidly low, and itss lagging my computer when its ran. Main.cpp [cpp]#include <iostream> #include <SFML/Graphics.hpp> #include "ball.h" #include "fps.hpp" int main() { // Create the main rendering window sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Gravity Ball"); // create frame counter object FPS frames; //creates new font // Load the font from a file sf::Font Vera; if (!Vera.LoadFromFile("Vera.ttf")){/* Error... */} //creates text string sf::Text Text; Text.SetFont(Vera); Text.SetCharacterSize(16); Text.SetColor(sf::Color(240, 240, 0)); Text.SetPosition(5.f, 5.f); // Start game loop while (App.IsOpened()) { // Process events sf::Event Event; while (App.GetEvent(Event)) { // Close window : exit if (Event.Type == sf::Event::Closed) App.Close(); } // Clear the screen (fill it with black color) App.Clear(); Text.SetString( "FPS: " + frames.GetFPS() ); std::cout << "FPS: " << frames.GetFPS() << std::endl; App.Draw(Text); // Display window contents on screen App.Display(); //add a frame to the counter frames.Update(); } return EXIT_SUCCESS; }[/cpp] fps.hpp I didnt create this one, found it on the net. [cpp]#ifndef FPS_HPP__INCLUDED #define FPS_HPP__INCLUDED #pragma once class FPS { // frame number unsigned int m_frame; // amount of frames so far unsigned int m_fps; // creates a clock to keep track of time an frames per second sf::Clock m_clock; public: FPS() : m_frame(0), m_fps(0) {} public: void Update(); const unsigned int GetFPS() const { return m_fps; } }; void FPS::Update() { if (m_clock.GetElapsedTime() >= 1.f) { m_fps = m_frame; m_frame = 0; m_clock.Reset(); } ++m_frame; } #endif // FPS_HPP__INCLUDED [/cpp] ball.h [cpp]#ifndef BALL_H_INCLUDED #define BALL_H_INCLUDED class MyBall : public sf::Shape { public: MyBall(); private: float mass, speed; float direction[2]; virtual ~MyBall(); }; #endif // BALL_H_INCLUDED [/cpp] ball.cpp [cpp] #include <SFML/Graphics.hpp> class MyBall : public sf::Shape { public: MyBall(); private: float mass, speed; float direction[2]; virtual ~MyBall(); }; [/cpp]
Why do you need a separate FPS class with another sf::Clock when sf::RenderWindow already has one?
How are you defining MyBall twice without an error? Are you sure it's loading the font right?
[QUOTE=sim642;25976489]Why do you need a separate FPS class with another sf::Clock when sf::RenderWindow already has one?[/QUOTE] How do i use RenderWindow fps counter? Will look at the documentation now. [QUOTE=ZeekyHBomb;25976510]How are you defining MyBall twice without an error? Are you sure it's loading the font right?[/QUOTE] How do you mean defining myball twice? And yea the font loads fine, displays FPS: for a second but then goes like the picture
You define the class once in ball.h and again in ball.cpp. Anyways, I now see the error: "FPS: " + frames.getFPS() is const char* + unsigned int. What you want is something like this: Text.SetString((std::ostringstream("FPS: ") << frames.getFPS()).str()); And about the RenderWindow FPS thing, you can use the RenderWindows frametime to calculate a FPS value.
What's up with [cpp]#ifndef FPS_HPP__INCLUDED #define FPS_HPP__INCLUDED #pragma once[/cpp] ?
[QUOTE=ZeekyHBomb;25976652]You define the class once in ball.h and again in ball.cpp. Anyways, I now see the error: "FPS: " + frames.getFPS() is const char* + unsigned int. What you want is something like this: Text.SetString((std::ostringstream("FPS: ") << frames.getFPS()).str()); And about the RenderWindow FPS thing, you can use the RenderWindows frametime to calculate a FPS value.[/QUOTE] Using that i get this error main.cpp|45|error: invalid use of incomplete type &#8216;struct std::ostringstream&#8217;| [editline]10th November 2010[/editline] [QUOTE=Overv;25976802]What's up with [cpp]#ifndef FPS_HPP__INCLUDED #define FPS_HPP__INCLUDED #pragma once[/cpp] ?[/QUOTE] Thats what it was like when i found it
[QUOTE=Overv;25976802]What's up with [cpp]#ifndef FPS_HPP__INCLUDED #define FPS_HPP__INCLUDED #pragma once[/cpp] ?[/QUOTE] #pragma once makes sure the header is looked at only once, leading to faster compile times. Without them, the compiler still needs to open and parse the file. Popular compilers try to detect header guards and imply that behavior, but - at least according to Andrei Alexandrescu - it is not perfect. [editline]10th November 2010[/editline] [QUOTE=Richy19;25976883]Using that i get this error main.cpp|45|error: invalid use of incomplete type &#8216;struct std::ostringstream&#8217;|[/QUOTE] #include <sstream>
Now im getting main.cpp|47|error: &#8216;struct std::basic_ostream<char, std::char_traits<char> >&#8217; has no member named &#8216;str&#8217;| I have included <string>
eh [cpp]//outside loop std::ostringstream converter; //inside loop converter.str("FPS: "); converter << frames.getFPS(); Text.SetString(converter.str());[/cpp]
AGhhh WTF now it says class FPS has no member named GetFPS [editline]10th November 2010[/editline] right im scratching the fps file, making my own [editline]10th November 2010[/editline] It seems that the number of frames is over writing the converter string so if i have 230 frames it shows up as 230: if i have 10 frames it shows 10S:
[QUOTE=Richy19;25976605]How do i use RenderWindow fps counter? Will look at the documentation now.[/QUOTE] [cpp]float Framerate = 1.f / App.GetFrameTime(); [/cpp] where App is an instance of sf::RenderWindow.
[QUOTE=sim642;25977258][cpp]float Framerate = 1.f / App.GetFrameTime(); [/cpp] where App is an instance of sf::RenderWindow.[/QUOTE] I seem to get around 400fps dont know if thats normal, seems like too little considering nothings happening
C's pseudorandom number generator isn't working quite like I need, so: In Lua, how can I remove the decimal point from a number? For example: magic(8.1) = 81 magic(0.3333333) = 3333333 magic(11.180339887499) = 11180339887499 If that's not possible (or fast), alternately, how can I get just the decimal of a number as an integer? magic2(14.56699) = 56699
You multiply the number by 10^(number of decimals) How to get the number of decimals in Lua, I don't have a clue. If all else fails, cast to string and then count the characters after the dot.
Maybe you should try to fix the actual problem rather than using a workaround. What's the problem with Cs PRNG?
Because using C's PRNG to choose "random" tiles in a game I'm making is giving me this: [img]http://dl.dropbox.com/u/3713769/temp/Image1.png[/img] ... Which doesn't look very random at all, does it? Anyway, I've answered my own question: tonumber((tostring(n):gsub("[^%d]", "")))
[QUOTE=Taehl;25978941]tonumber((tostring(n):gsub("[^%d]", "")))[/QUOTE] Why not just do tonumber((tostring(n):gsub("%.", "")))?
That works too. Unfortunately, the tonumber((tostring method produces quite a bit of overhead... I don't suppose there's a more optimal way to do it?
[QUOTE=MakeR;25979070]Why not just do tonumber((tostring(n):gsub("%.", "")))?[/QUOTE] That could cause problems with different system locales. There are some cases where tostring(51.224) could result in 51,224.
[QUOTE=Taehl;25978941]Because using C's PRNG to choose "random" tiles in a game I'm making is giving me this: [img_thumb]http://dl.dropbox.com/u/3713769/temp/Image1.png[/img_thumb] ... Which doesn't look very random at all, does it? Anyway, I've answered my own question: tonumber((tostring(n):gsub("[^%d]", "")))[/QUOTE] If you're using the modulus operator, it's supposedly bad. [url]http://www.facepunch.com/threads/949277-What-are-You-Working-On-V-0xB?p=22795662[/url] Try that method, and if it fails maybe look for an implementation of mersenne twister for C.
[QUOTE=ZeekyHBomb;25979821]--maybe look for an implementation of mersenne twister for C.[/QUOTE] Or just look it up on Wikipedia. The pseudocode in there could almost directly be translated to C, even I could do it.
Argh. So I have these 2 .h files, and they need to expose each other to work, so there is a circular refernece. I put class SomeClass; at the top of one of them, but then I just get 'w/e' has an incomplete type. (w/e is a member of the class.
Redesign. You might be able to use pointers or references, in which case an incomplete type will suffice for the declaration, but circular dependency is usually a sign of suboptimal design.
[QUOTE=ZeekyHBomb;25980732]Redesign. You might be able to use pointers or references, in which case an incomplete type will suffice for the declaration, but circular dependency is usually a sign of suboptimal design.[/QUOTE] Basically I have a tile class and a base entity class. The tile class needs to store the entity on top of it, and the entity needs to get an array of the tiles around it. I suppose I could make it so that the entity only needs an array of the entity's around it and stores the tile it's on and the tile doesn't know about it at all but I need the tile to know about it for collisions... [editline]10th November 2010[/editline] Edit: Nevermind, I needed to redesign it anyway. All fixed. Now however, I have a for loop that loops through a vector of entites, and I need to pass a vector[i] to a function. How do I pass it? None of the things I tried worked. [editline]10th November 2010[/editline] Edit: Nevermind, I needed to redesign it anyway. All fixed. Now however, I have a for loop that loops through a vector of entites, and I need to pass a vector[i] to a function. How do I pass it? None of the things I tried worked.
Sorry, you need to Log In to post a reply to this thread.