• What do you need help with? Version 1
    5,001 replies, posted
Ah, thanks. I misunderstood the concept of static then. Any suggestions for what I might use to achieve my goal?
-snip-
A static global variable is private to a .cpp file. You can declare it as [cpp] extern unsigned char Error; [/cpp] in the header and define it [cpp] unsigned char Error = 0; [/cpp] in ScriptCom.cpp
Awesome, works like a charm. Thanks!
Having some problems with C++. Coming from C#, I fuck up most of the syntax. Here's my code so far. [b]Main.cpp[/b] [cpp]#include <SFML/System.hpp> #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <iostream> int main() { sf::RenderWindow App(sf::VideoMode(800, 600, 32), "WinterEscape"); sf::Image Tex(32, 32, sf::Color::White); Entity Ent; Ent.Sprite::SetImage(Tex); while (App.IsOpened()) { sf::Event Event; while (App.GetEvent(Event)) { if (Event.Type == sf::Event::Closed) App.Close(); } App.Clear(sf::Color(40, 70, 125)); Ent.Draw(App); App.Display(); } return EXIT_SUCCESS; }[/cpp] [b]Entities/Entity.cpp[/b] [cpp]#include <SFML/System.hpp> #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <iostream> class Entity { public: sf::Sprite Sprite; Entity() { Sprite = sf::Sprite(); } ~Entity() { } void Draw(sf::RenderWindow App) { App.Draw(Sprite); } };[/cpp] It whines about not being able to find the class name "Entity", so apparently it doesn't read the Entity.cpp file. How do I fix this? [editline]24th December 2010[/editline] [cpp]#include "Entities/Entity.cpp"[/cpp] Says: [quote]Cannot open include file: 'Entities/Entity.cpp': No such file or directory[/quote]
You don't include .cpp files from other .cpp files. Put the class definition in a header file (e.g. Entity.hpp) and include that. The implementation of the class's methods goes in Entity.cpp. Syntactically that #include looks right, though. If it can't find the file then it's something with the paths in your project. Where is that Entities directory located?
[QUOTE=Chris220;26927250]You have to compile sfml-system first on all four build targets.[/QUOTE] Thanks but I found out that when I compiled sfml-system, it had named it libsfml-system-d.dll.a so i just removed the .dll part so that it could find it. Thanks anyways Chris :)
[QUOTE=Wyzard;26932113]You don't include .cpp files from other .cpp files. Put the class definition in a header file (e.g. Entity.hpp) and include that. The implementation of the class's methods goes in Entity.cpp. Syntactically that #include looks right, though. If it can't find the file then it's something with the paths in your project. Where is that Entities directory located?[/QUOTE] Nevermind, I rewrote the whole project using headers and now it all works :buddy: Thanks!
[QUOTE=awfa3;26933241]Thanks but I found out that when I compiled sfml-system, it had named it libsfml-system-d.dll.a so i just removed the .dll part so that it could find it. Thanks anyways Chris :)[/QUOTE] I wonder why it did that... how strange! Ah well, glad to hear it's working.
Yea it was pretty confusing
Since I'm absolute shit with C++, I can't figure out why [url=http://pastie.org/private/8vqpfvepggo0oupnn2ww]this[/url] code crashes when the function ends and the runtime calls the destructor of the Elements vector. Stack trace: [img]http://imgur.com/tUj6V.png[/img] What am I doing wrong? (also, yes, the code is messy and needs some stupid little optimizations like not calling .size() every time. But right now I just want to get it to work.)
What's the crash message? And why are you allocating Elements.size() / 3 GLuints, but stuff in Elements.size() elements? Instead of using an index to go through each index, you could also use an iterator for the m_* vectors. And even more efficient: a std::memcpy for the Elements-vector (since it's a POD type). Also be careful when passing a this-pointer to other functions from the constructor.
[QUOTE=ZeekyHBomb;26939039]What's the crash message?[/QUOTE] Breakpoint encountered at HeapFree in _free_base @free.c. [QUOTE=ZeekyHBomb;26939039]And why are you allocating Elements.size() / 3 GLuints, but stuff in Elements.size() elements?[/QUOTE] Because I'm a fucking retard? It doesn't crash anymore now - I guess I just overflowed the heap like hell. [QUOTE=ZeekyHBomb;26939039]Instead of using an index to go through each index, you could also use an iterator for the m_* vectors.[/QUOTE] Oh, I didn't know about that. [QUOTE=ZeekyHBomb;26939039]And even more efficient: a std::memcpy for the Elements-vector (since it's a POD type).[/QUOTE] Oh, that is awesome, I had no idea. I guess I really need to read up more about the STL. Anyhow, fixed. Thanks a bunch!
Why can't I compare the getf() values? lowestfscore somehow always wins, even though no value is above 255. [cpp]ctile * lowestfscore = new ctile; lowestfscore->set(255, 255); for(std::list<ctile *>::iterator i = openlist.begin(); i != openlist.end(); i++) if((*i)->getf() < lowestfscore->getf()) lowestfscore = *i; [/cpp]
Strip down your code to a barebone testcase and post that; there's not enough information in your currently posted code.
[QUOTE=ZeekyHBomb;26940255]Strip down your code to a barebone testcase and post that; there's not enough information in your currently posted code.[/QUOTE] Who me?
Yes. [editline]25th December 2010[/editline] And I mean a testcase that I can compile without modifications; shouldn't really take long to code...
[QUOTE=ZeekyHBomb;26940532]Yes. [editline]25th December 2010[/editline] And I mean a testcase that I can compile without modifications; shouldn't really take long to code...[/QUOTE] I recreated it but it works now. Guess I'll debug my current code. [editline]24th December 2010[/editline] Ok here is the code in it's entirety. I have no idea how to fix it. [url]http://pastebin.com/EUdNktTs[/url]
If anybody can read that, I'll be damned.
[QUOTE=Jookia;26944317]If anybody can read that, I'll be damned.[/QUOTE] I thought I formated it well :saddowns:
Formatting doesn't mean readable.
My map is rendering white. FreeImage is loading the image. [cpp] // Image.cpp Image::Image(const std::string& Path) : m_Id(0), m_Width(0), m_Height(0), m_Data(0) { FREE_IMAGE_FORMAT Format = FreeImage_GetFileType(Path.c_str(), 0); if(Format == FIF_UNKNOWN) Format = FreeImage_GetFIFFromFilename(Path.c_str()); if(Format == FIF_UNKNOWN) return; FIBITMAP* Dib = 0; if(FreeImage_FIFSupportsReading(Format)) Dib = FreeImage_Load(Format, Path.c_str()); if(!Dib) return; m_Data = FreeImage_GetBits(Dib); m_Width = FreeImage_GetWidth(Dib); m_Height = FreeImage_GetHeight(Dib); if(!m_Data || !m_Width || !m_Height) return; glGenTextures(1, &m_Id); glBindTexture(GL_TEXTURE_2D, m_Id); glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_BGR_EXT, m_Width, m_Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, m_Data); FreeImage_Unload(Dib); } // Map/Renderer.cpp MapRenderer::MapRenderer(Map* Map, Image* Tileset) : m_Map(Map), m_pVertices(0), m_pVerticesUvCoords(0), m_pVerticesColor(0) { int Size = m_Map->GetWidth() * m_Map->GetHeight(); m_pVertices = new glVertex[Size * 3 * 2]; m_pVerticesUvCoords = new glUvCoords[Size * 3 * 2]; m_pVerticesColor = new long[Size * 3 * 2]; m_VerticesCount = Size * 3 * 2; for(int i = 0; i < m_VerticesCount; ++i) { m_pVertices[i].z = 0.5f; } Tileset->Bind(); int Vertices = 0; for(int w = 0; w < m_Map->GetWidth(); ++w) { for(int h = 0; h < m_Map->GetHeight(); ++h) { AddVertex(w * m_Map->GetTilesize(), h * m_Map->GetTilesize(), 1.0f, 1.0f, Vertices); AddVertex(w * m_Map->GetTilesize() + m_Map->GetTilesize(), h * m_Map->GetTilesize(), 0.0f, 1.0f, Vertices + 1); AddVertex(w * m_Map->GetTilesize(), h * m_Map->GetTilesize() + m_Map->GetTilesize(), 1.0f, 0.0f, Vertices + 2); AddVertex(w * m_Map->GetTilesize() + m_Map->GetTilesize(), h * m_Map->GetTilesize(), 0.0f, 1.0f, Vertices + 3); AddVertex(w * m_Map->GetTilesize() + m_Map->GetTilesize(), h * m_Map->GetTilesize() + m_Map->GetTilesize(), 0.0f, 0.0f, Vertices + 4); AddVertex(w * m_Map->GetTilesize(), h * m_Map->GetTilesize() + m_Map->GetTilesize(), 1.0f, 0.0f, Vertices + 5); Vertices += 6; } } } void MapRenderer::Render() { if(m_VerticesCount > 0) { glVertexPointer(3, GL_FLOAT, sizeof(glVertex), (const GLvoid *)m_pVertices); glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(long), (const GLvoid*)m_pVerticesColor); glEnableClientState(GL_COLOR_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(glUvCoords), (const GLvoid *)m_pVerticesUvCoords); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDrawArrays(GL_TRIANGLES, 0, (GLsizei)m_VerticesCount); glFlush(); } } void MapRenderer::AddVertex(float X, float Y, float U, float V, int Vertex) { m_pVertices[Vertex].x = -0.5f + X; m_pVertices[Vertex].y = -0.5f + Y; m_pVerticesUvCoords[Vertex].u = U; m_pVerticesUvCoords[Vertex].v = V; m_pVerticesColor[Vertex] = 0xFFFFFFFF; } [/cpp]
[QUOTE=WTF Nuke;26941083]I recreated it but it works now. Guess I'll debug my current code. [editline]24th December 2010[/editline] Ok here is the code in it's entirety. I have no idea how to fix it. [url]http://pastebin.com/EUdNktTs[/url][/QUOTE] Well documented code I see... Well, it's far from barebone and also not compilable without additional code and guesswork on that.
[QUOTE=WTF Nuke;26941083]I recreated it but it works now. Guess I'll debug my current code. [editline]24th December 2010[/editline] Ok here is the code in it's entirety. I have no idea how to fix it. [url]http://pastebin.com/EUdNktTs[/url][/QUOTE] A few comments scattered around would make that a lot easier to understand
[QUOTE=DevBug;26945905]My map is rendering white. FreeImage is loading the image. [cpp] // Image.cpp Image::Image(const std::string& Path) : m_Id(0), m_Width(0), m_Height(0), m_Data(0) { FREE_IMAGE_FORMAT Format = FreeImage_GetFileType(Path.c_str(), 0); if(Format == FIF_UNKNOWN) Format = FreeImage_GetFIFFromFilename(Path.c_str()); if(Format == FIF_UNKNOWN) return; FIBITMAP* Dib = 0; if(FreeImage_FIFSupportsReading(Format)) Dib = FreeImage_Load(Format, Path.c_str()); if(!Dib) return; m_Data = FreeImage_GetBits(Dib); m_Width = FreeImage_GetWidth(Dib); m_Height = FreeImage_GetHeight(Dib); if(!m_Data || !m_Width || !m_Height) return; glGenTextures(1, &m_Id); glBindTexture(GL_TEXTURE_2D, m_Id); glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_BGR_EXT, m_Width, m_Height, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, m_Data); FreeImage_Unload(Dib); } // Map/Renderer.cpp MapRenderer::MapRenderer(Map* Map, Image* Tileset) : m_Map(Map), m_pVertices(0), m_pVerticesUvCoords(0), m_pVerticesColor(0) { int Size = m_Map->GetWidth() * m_Map->GetHeight(); m_pVertices = new glVertex[Size * 3 * 2]; m_pVerticesUvCoords = new glUvCoords[Size * 3 * 2]; m_pVerticesColor = new long[Size * 3 * 2]; m_VerticesCount = Size * 3 * 2; for(int i = 0; i < m_VerticesCount; ++i) { m_pVertices[i].z = 0.5f; } Tileset->Bind(); int Vertices = 0; for(int w = 0; w < m_Map->GetWidth(); ++w) { for(int h = 0; h < m_Map->GetHeight(); ++h) { AddVertex(w * m_Map->GetTilesize(), h * m_Map->GetTilesize(), 1.0f, 1.0f, Vertices); AddVertex(w * m_Map->GetTilesize() + m_Map->GetTilesize(), h * m_Map->GetTilesize(), 0.0f, 1.0f, Vertices + 1); AddVertex(w * m_Map->GetTilesize(), h * m_Map->GetTilesize() + m_Map->GetTilesize(), 1.0f, 0.0f, Vertices + 2); AddVertex(w * m_Map->GetTilesize() + m_Map->GetTilesize(), h * m_Map->GetTilesize(), 0.0f, 1.0f, Vertices + 3); AddVertex(w * m_Map->GetTilesize() + m_Map->GetTilesize(), h * m_Map->GetTilesize() + m_Map->GetTilesize(), 0.0f, 0.0f, Vertices + 4); AddVertex(w * m_Map->GetTilesize(), h * m_Map->GetTilesize() + m_Map->GetTilesize(), 1.0f, 0.0f, Vertices + 5); Vertices += 6; } } } void MapRenderer::Render() { if(m_VerticesCount > 0) { glVertexPointer(3, GL_FLOAT, sizeof(glVertex), (const GLvoid *)m_pVertices); glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(long), (const GLvoid*)m_pVerticesColor); glEnableClientState(GL_COLOR_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(glUvCoords), (const GLvoid *)m_pVerticesUvCoords); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDrawArrays(GL_TRIANGLES, 0, (GLsizei)m_VerticesCount); glFlush(); } } void MapRenderer::AddVertex(float X, float Y, float U, float V, int Vertex) { m_pVertices[Vertex].x = -0.5f + X; m_pVertices[Vertex].y = -0.5f + Y; m_pVerticesUvCoords[Vertex].u = U; m_pVerticesUvCoords[Vertex].v = V; m_pVerticesColor[Vertex] = 0xFFFFFFFF; } [/cpp][/QUOTE] glVertexPointer is deprecated, why are you using it?
[QUOTE=Darwin226;26950662]glVertexPointer is deprecated, why are you using it?[/QUOTE] Don't get on my case about deprecated code.
How do I get the inverse of ^z$ in regex so that it would match everything else than ^z$ ?
Yeah sorry about that, I coded that when I was tired. Bad idea. Anyway I'll make a standalone version with better documentation, just give me a bit. Edit: Ok it's x-mas and I'm lazy. Will get it done tomorrow.
[QUOTE=DevBug;26954156]Don't get on my case about deprecated code.[/QUOTE] It's ok if you can't handle it XD
[QUOTE=Darwin226;26950662]glVertexPointer is deprecated, why are you using it?[/QUOTE] Because Khronos seems to have fun deprecating everything from version to version, so people stop giving a fuck if method x is deprecated, and they're right.
Sorry, you need to Log In to post a reply to this thread.