• What do you need help with? Version 5
    5,752 replies, posted
  • [QUOTE=Naelstrom;36178926]I guess someone is not feeling adventurous today. :([/QUOTE] You clearly have not used Git for Windows
  • Trying to create a method that returns an array but its just not being as easy as I want it too. I tired googling this problem but none seem to fit my situation. [cpp] Entity * GameObjectManager::getInt(Entity::entityName name) { std::map<int, Entity*>::const_iterator results = _gameObjects.begin(); static Entity * r[10]; int index = 0; if(results->second->name == name) { r[index] = results->second; index++; } return r; } [/cpp]
  • [QUOTE=esalaka;36186947]Return a vector.[/QUOTE] This has to be a super hacky way of doing this but I cannot think of any other way to do this. [cpp] std::map<int, Entity*> GameObjectManager::getGroup(Entity::entityName name) { std::map<int, Entity*>::const_iterator itr = _gameObjects.begin(); std::map<int, Entity*> temp; while(itr != _gameObjects.end()) { if(itr->second->name == name) { temp.insert(std::pair<int,Entity*>(itr->second->getID(),itr->second)); } itr++; } return temp; std::for_each(temp.begin(),temp.end(),GameObjectDeallocator()); } [/cpp] [cpp] std::map<int, Entity*> tempArray = Main::GetGameObjectManager().getGroup(Entity::entityName::entityBullet); std::map<int, Entity*>::const_iterator itr = tempArray.begin(); while(itr != tempArray.end()) { if(itr->second->GetBoundingRect().intersects(GetBoundingRect())) { SetPosition(0,0); Main::GetGameObjectManager().Remove(itr->second->getID()); } itr++; } [/cpp]
  • [QUOTE=Jimmylaw;36187139]This has to be a super hacky way of doing this but I cannot think of any other way to do this. [cpp] std::map<int, Entity*> GameObjectManager::getGroup(Entity::entityName name) { std::map<int, Entity*>::const_iterator itr = _gameObjects.begin(); std::map<int, Entity*> temp; while(itr != _gameObjects.end()) { if(itr->second->name == name) { temp.insert(std::pair<int,Entity*>(itr->second->getID(),itr->second)); } itr++; } return temp; std::for_each(temp.begin(),temp.end(),GameObjectDeallocator()); } [/cpp] [cpp] std::map<int, Entity*> tempArray = Main::GetGameObjectManager().getGroup(Entity::entityName::entityBullet); std::map<int, Entity*>::const_iterator itr = tempArray.begin(); while(itr != tempArray.end()) { if(itr->second->GetBoundingRect().intersects(GetBoundingRect())) { SetPosition(0,0); Main::GetGameObjectManager().Remove(itr->second->getID()); } itr++; } [/cpp][/QUOTE] Give it a reference instead to avoid copying the std::map. [cpp] void GameObjectManager::getGroup(Entity::entityName name, std::map<int, Entity*> &list) { list.clear(); std::map<int, Entity*>::const_iterator itr = _gameObjects.begin(); while(itr != _gameObjects.end()) { if(itr->second->name == name) { list.insert(std::pair<int,Entity*>(itr->second->getID(),itr->second)); } itr++; } std::for_each(list.begin(),list.end(),GameObjectDeallocator()); } [/cpp] [cpp] std::map<int, Entity*> tempArray; Main::GetGameObjectManager().getGroup(Entity::entityName::entityBullet, tempArray); std::map<int, Entity*>::const_iterator itr = tempArray.begin(); while(itr != tempArray.end()) { if(itr->second->GetBoundingRect().intersects(GetBoundingRect())) { SetPosition(0,0); Main::GetGameObjectManager().Remove(itr->second->getID()); } itr++; } [/cpp]
  • [QUOTE=Z_guy;36187491]Give it a reference instead to avoid copying the std::map. [/QUOTE] Either I'm being slow or I just don't understand this but how does the updated "tempArray" get passed back from getGroup method to the function that wants it? Or it is because your passing it a pointer and not an object?
  • [QUOTE=Jimmylaw;36187673]Either I'm being slow or I just don't understand this but how does the updated "tempArray" get passed back from getGroup method to the function that wants it? Or it is because your passing it a pointer and not an object?[/QUOTE] [cpp]std::map<int, Entity*> &list[/cpp] Notice the &-sign? That means you're passing in a reference, which works kind of like a pointer. It means you're passing in the actual object instead of a copy of it.
  • So i am mucking around with the Farseer Physics Engine. I'm running into issues loading content with Debug View. [code]DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);[/code] When this code is run, i get "Error loading "font". File not found." How should i fix this? I assume that ScreenManager.Content is empty or something and it's attempting to load a font that doesn't exist or something.
  • This sort of thing is a bit beyond my understand right now, but basically I am doing some bit twiddling. However, I am not sure if my pack function is correct, it seems to work properly but I am just not sure and would like insight from a more experienced programmer. [url]http://pastebin.com/v1dsdWnH[/url] Also, I am aware that the function names are poop.
  • I've been programming for quite some time now (five courses in 2.5 years, one introductory course taught in C++ which I finished during my first year, in a week. I had two C++ and two Java courses during my second and third year), with excellent grades. I know much of learning to program is to just practice and experiment by yourself, and that I have done, but I feel like I'm not advancing any more in C++. I have a good grasp of classes and pointers in C++ and I've been doing some 2d work in SDL and SFML. I've started nosing about with templates in C++ but I haven't found anything interesting to use them with, yet (finding them quite hard to understand right now, actually) Suggestions? and what should I try to focus on doing after that?
  • so I'm trying to find a method to optimize drawing with rectangles, using the least amount of rects possible. I got it to check horizontally: [img]http://puu.sh/ySLm[/img] but no matter how hard I try, I can't get it to check vertically as well. The code is really ugly, but the logical steps behind how I did it are like this: [code] at pixel (x, y) check horizontally if the colors are the same repeat at (x + 1, y) else check downwards for the whole rectangle if all the colors are the same repeat at (x, y + 1) else back up, store the rectangle end end end [/code] I don't even know if the rectangles are just getting overlapped, because LOVE sucks with debugging is there a better way to do this? or an example I can look at?
  • I've been stuck with this for a while, I'm hoping that WDYNHW will be my savior. I've been trying to make a 2D platformer forever, one similar to SMB or Megaman. I know how to draw everything and get moving, but how would I make it so if it collided with a certain area (such as a wall) it would stop jumping, stop moving, or whatever. I can't figure this one out.
  • How do big devs handle things like entity systems? I know they are usually component based and before I start writing code I want to plan this out, lest I get awful and incomprehensible code that I just don't want to deal with. Like what does gamebryo do?
  • [QUOTE=WTF Nuke;36204242]How do big devs handle things like entity systems? I know they are usually component based and before I start writing code I want to plan this out, lest I get awful and incomprehensible code that I just don't want to deal with. Like what does gamebryo do?[/QUOTE] This one is actually really easy on yourself, considering things with the source engine. Just get the source code for modding, and look at the entity cpp and header files.
  • [QUOTE=WTF Nuke;36204242]Like what does gamebryo do?[/QUOTE] Nothing that you want to replicate.
  • [QUOTE=WTF Nuke;36204242]How do big devs handle things like entity systems? I know they are usually component based and before I start writing code I want to plan this out, lest I get awful and incomprehensible code that I just don't want to deal with. Like what does gamebryo do?[/QUOTE] As long as you define components by functionality and not by the type of an object, you really can't go that wrong with a component based entity system. Before I implemented that type of system for the first time, I kept on thinking that it would be really complicated and that it would be hard to build the proper framework around it, etc. Then at some point I just started writing some code and realized that a lot of the complications I thought of were non-issues and a lot of things worked themselves out. The only planning you really need to do right now before you write code: -What data is shared between all components and should be a part of Entity? (hint: position) -How will components communicate with one another? (In my implementation all components store a reference to their parent Entity, and you can request other components through the Entity. Other implementations do things like a message passing interface. Depends on what you need.) -how will I store all the components and update them? (Usually this involves a ComponentManager or something similar. In my implementation it only accepts Entities, but internally stores them as separate components separated by type.) Once you have a plan for those three things, start writing some code and you'll see that a lot of it will start to fall in place.
  • Having a problem with "'Particle' : base class undefined" after lots of google search it appears its causes by an issue with 2 classes having the same header file but this is not the case with mine. [cpp] #pragma once #include "Particle.h" class blueParticle :public Particle { public: blueParticle(int x, int y, float dirx, float diry); virtual ~blueParticle(); protected: }; [/cpp] [cpp] #pragma once #include "Entity.h" #include "Main.h" class Particle : public Entity { public: Particle(int x, int y, float dirx, float diry); virtual ~Particle(); virtual void Update(float frametime); protected: float life_time_; sf::Vector2f direction; float timeAcc; }; [/cpp]
  • Does Main.h or Entity.H include blueParticle.h/Particle.h? I don't see any reason for your Particle class to include "Main.h" either.
  • Does anyone know what are some good values for perlin noise? Im using these values: [cpp] PerlinNoise p; p.Set( 2.25, //Persistance 4.0, //Frequency 0.50, //Amplittude 6, //Octaves 5555); //Seed glGenTextures( 1, &tex ); glBindTexture( GL_TEXTURE_2D, tex ); int imgSize = 512; glm::vec3 img[imgSize*imgSize]; for(int y = 0; y < imgSize; y++) { for(int x = 0; x < imgSize; x++) { int id = x + (y * imgSize); img[id] = glm::vec3(p.GetHeight(x, y)); } } glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, imgSize, imgSize, 0, GL_RGB, GL_FLOAT, img ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glGenerateMipmap( GL_TEXTURE_2D ); [/cpp] But it gives this ugly thing: [IMG]http://i.imgur.com/cU93T.png[/IMG]
  • Tried setting up a basic opengl window with glut and then binding a shader to it with glew, for some reason the shader doesn't do anything, does anybody have any idea why ? Source : [url]http://dl.dropbox.com/u/28926055/EmpiresOpenGL.rar[/url]
  • [QUOTE=quincy18;36211174]Tried setting up a basic opengl window with glut and then binding a shader to it with glew, for some reason the shader doesn't do anything, does anybody have any idea why ? Source : [url]http://dl.dropbox.com/u/28926055/EmpiresOpenGL.rar[/url][/QUOTE] You should add shader error checking. You're blindly compiling and linking the shader without actually checking if it succeeded or not. You can use my engine's shader object for reference if you'd like, but it's a little messy: [url]https://github.com/naelstrof/Astrostruct/blob/master/src/NShader.cpp[/url]
  • Yea, I figured that much, so I added it in and this was the error : [URL]http://dl.dropbox.com/u/28926055/juulbitch.png[/URL] But the vertex and fragment shader are both really simple, can't find anything that could cause this. - Edit - Managed to fix the error by removing the #version 150 but now it doesn't error and still just displays a white cube instead of a yellow one.
  • Currently messing around with SAT (Separating Axis Theorem), But failing miserably to produce a decent collision response. Does anyone have any examples or old code to share and learn from?
  • Can anyone see anything wrong with this perlin class, I cant get the desired output. [cpp]#include "PerlinNoise.hpp" PerlinNoise::PerlinNoise() { persistence = 0; frequency = 0; amplitude = 0; octaves = 0; randomseed = 0; } PerlinNoise::PerlinNoise(double _persistence, double _frequency, double _amplitude, int _octaves, int _randomseed) { persistence = _persistence; frequency = _frequency; amplitude = _amplitude; octaves = _octaves; randomseed = 2 + _randomseed * _randomseed; } void PerlinNoise::Set(double _persistence, double _frequency, double _amplitude, int _octaves, int _randomseed) { persistence = _persistence; frequency = _frequency; amplitude = _amplitude; octaves = _octaves; randomseed = 2 + _randomseed * _randomseed; } double PerlinNoise::GetHeight(double x, double y) const { return amplitude * Total(x, y); } double PerlinNoise::Total(double i, double j) const { //properties of one octave (changing each loop) double t = 0.0f; double _amplitude = 1; double freq = frequency; for(int k = 0; k < octaves; k++) { t += GetValue(j * freq + randomseed, i * freq + randomseed) * _amplitude; _amplitude *= persistence; freq *= 2; } return t; } double PerlinNoise::GetValue(double x, double y) const { int Xint = (int)x; int Yint = (int)y; double Xfrac = x - Xint; double Yfrac = y - Yint; //noise values double n01 = Noise(Xint-1, Yint-1); double n02 = Noise(Xint+1, Yint-1); double n03 = Noise(Xint-1, Yint+1); double n04 = Noise(Xint+1, Yint+1); double n05 = Noise(Xint-1, Yint); double n06 = Noise(Xint+1, Yint); double n07 = Noise(Xint, Yint-1); double n08 = Noise(Xint, Yint+1); double n09 = Noise(Xint, Yint); double n12 = Noise(Xint+2, Yint-1); double n14 = Noise(Xint+2, Yint+1); double n16 = Noise(Xint+2, Yint); double n23 = Noise(Xint-1, Yint+2); double n24 = Noise(Xint+1, Yint+2); double n28 = Noise(Xint, Yint+2); double n34 = Noise(Xint+2, Yint+2); //find the noise values of the four corners double x0y0 = 0.0625*(n01+n02+n03+n04) + 0.125*(n05+n06+n07+n08) + 0.25*(n09); double x1y0 = 0.0625*(n07+n12+n08+n14) + 0.125*(n09+n16+n02+n04) + 0.25*(n06); double x0y1 = 0.0625*(n05+n06+n23+n24) + 0.125*(n03+n04+n09+n28) + 0.25*(n08); double x1y1 = 0.0625*(n09+n16+n28+n34) + 0.125*(n08+n14+n06+n24) + 0.25*(n04); //interpolate between those values according to the x and y fractions double v1 = Interpolate(x0y0, x1y0, Xfrac); //interpolate in x direction (y) double v2 = Interpolate(x0y1, x1y1, Xfrac); //interpolate in x direction (y+1) double fin = Interpolate(v1, v2, Yfrac); //interpolate in y direction return fin; } double PerlinNoise::Interpolate(double x, double y, double a) const { double negA = 1.0 - a; double negASqr = negA * negA; double fac1 = 3.0 * (negASqr) - 2.0 * (negASqr * negA); double aSqr = a * a; double fac2 = 3.0 * aSqr - 2.0 * (aSqr * a); return x * fac1 + y * fac2; //add the weighted factors } double PerlinNoise::Noise(int x, int y) const { int n = x + y * 57; n = (n << 13) ^ n; int t = (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff; return 1.0 - double(t) * 0.931322574615478515625e-9;/// 1073741824.0); } [/cpp]
  • ActionScript 3, pretty much my first game ever. [QUOTE] if //scorer1 reaches 200 { //Go to scene 2 and play } } [/QUOTE] I want the game to go to scene 2 and play after [I]scorer1[/I] reaches 200. scorer1 is the instance name of the text box displaying the score. I know how to modify numeral values when they are a string [QUOTE]if blah blah { scorer1.text=(int(scorer1.text)+1).toString()[/QUOTE]but I don't know how to detect when a string has become a certain value. Learning AS3 at school as first programming language. I'll be moving onto harder stuff next year. Sorry my coding isn't as grand as that noise-simulator thingy made in Perl above :/
  • [QUOTE=quincy18;36211676]Yea, I figured that much, so I added it in and this was the error : [URL]http://dl.dropbox.com/u/28926055/juulbitch.png[/URL] But the vertex and fragment shader are both really simple, can't find anything that could cause this. - Edit - Managed to fix the error by removing the #version 150 but now it doesn't error and still just displays a white cube instead of a yellow one.[/QUOTE] Your shaders use very old deprecated OpenGL features, so GLSL 1.50 is definitely not suited for you. Using a [i]glGetError()[/i] I found that [i]glUseProgram[/i] was causing a [i]GL_INVALID_VALUE[/i] error. To see why this happens, let's have a look at shader creation: [cpp]shader = Shader("Shaders\\vertexshader.shader", "Shaders\\pixelshader.shader");[/cpp] What happens here is that a shader object is created and loads the shaders you specified. It is then assigned to the [i]shader[/i] variable and finally it destroys itself because it is no longer necessary. This destruction causes the shaders to be unloaded and they will no longer be usable by your program. To circumvent this, you need to implement your own assignment operator: [cpp]Shader& Shader::operator=( Shader& shader ) { shader_vp = shader.shader_vp; shader_fp = shader.shader_fp; shader_id = shader.shader_id; shader.shader_id = 0; return *this; }[/cpp] And tell the destructor to not do anything if no shader program is set: [cpp]Shader::~Shader(void) { if ( shader_id == 0 ) return;[/cpp] And of course initialise it to be 0: [cpp]Shader::Shader() { shader_id = 0; }[/cpp] This will result in a correctly drawn cylinder. [t]http://puu.sh/z6ay[/t] Really though, the OpenGL code used here is depressing. If you want to use glut, fair enough, but using fixed pipeline properties in shaders? Ugh. If you have some pride, either ditch shaders or switch to full programmable mode.
  • Is there any easier way than putting all my .lua files with main.lua on top in a .zip, change it to a .love and execute it everytime I make a small change? Lua + Love2D.
  • In unity I'm trying to figure out how to change a texture at runtime in C#. I have the file name of the texture in a string, but I dont know how to set the texture from a path.
  • [QUOTE=TM Gmod;36220901]In unity I'm trying to figure out how to change a texture at runtime in C#. I have the file name of the texture in a string, but I dont know how to set the texture from a path.[/QUOTE] here's one way at least [cpp] using System.IO; private Texture2D loadTexture(string name){ byte[] png = File.ReadAllBytes(name); //name is a full path Texture2D temp; //= new Texture2D(1,1); //i don't remember if you need to initialize it beforehand temp.LoadImage(png); temp.filterMode = FilterMode.Point; //pixelated by default (use whichever mode you'd like) temp.wrapMode = TextureWrapMode.Clamp; //don't repeat the texture return temp; }[/cpp]