Tag Info

Hot answers tagged

17

If you rely on your code in order to pay for food and shelter, and you need to support cross-platform on unknown future platforms (or reasonably might need to support cross-platform in the future), then designing your code to rely on a bunch of unknown compiler writers' correct adherence to bleeding edge language standards is dangerous (and I would argue, ...


8

Smart pointers or handle classes, just like C++11. You could write your own long before C++11. I would even argue that the shared_ptr in C++11 is probably the wrong model entirely. All you do is make a type that holds a reference to a resource. This reference could be a pointer with some kind of lifetime management or it could just be some kind of numeric ...


6

Instead of holding raw pointers, hold some other lightweight reference to the resource. A shared_ptr and corresponding weak_ptr instances are one such mechanism, but you can easily implement your own if you don't have access to those types (or their earlier Boost equivalents) or there are other reasons why those types would not be appropriate for your ...


6

If your willing to do a bit more work, you could look into refractoring solutions. clang has some interesting stuff happening in that area currently. It should be possible to use the auto keyword, run it through the refactorer which will find all uses of it, resolve them for you and output the code then compile it with whatever you want. But that means ...


5

First: Game Industry is moving really, really slow. It's a huge (financial sense) industry, so there are always many people against everything which is new/unknown/maybe smarter than them and/or no competitor uses it and/or no projects are known which were successful using this new stuff. some kind of catch-22. Second: Performance matters. Way (!) more ...


5

Your game loop code is correct, but your units are all mixed up -- you are effectively setting to your timestep to .00000003 nanoseconds! Your clock is counting in nanoseconds, so your dt should be in nanoseconds. If a clock ticks 30 times a second, it will tick every .033 seconds. There are many nanoseconds in a second, so it will take more nanoseconds to ...


5

Depending on your needs there are different data structure that you can use for geometry representation, before I answer your question I need to point out that geometric representation are usually chosen based on two basic factors, Topological Requirements: this includes the types of meshes you are going to store, triangles only? n-polys ? regular, ...


5

Half-edges are usually used for many serious geometrical analysis and modification algorithms. You may find it more convenient to add a higher-level abstraction layer on top of this if you don't want to work with half-edges directly.


4

How to I implement a variable number of threads that all execute at the same time? Build/use a container class (I would call it a ThreadPool) for holding threads or thread references (note that std::thread is only movable and not copyable), each time one of the threads is started it is not joined by default. Wehn ThreadPool is going to be destructed ...


4

Using tiles is a great idea first off (for a 2d game), as it allows you to effectively manage memory, loading, etc. and an effective part of using tiles for this reason IS to use a matrix, or map. In combination with a tileset for a given level or area, and with your base reflections (x and y plane) the matrix/map and tileset combo works a treat. Three ...


3

Easiest is to use stringstream and check if conversion to int succeeded (reached eof) #include "sstream" //your code cout << "Enter a guess: "; std::string str; cin >> str; std::istringstream iss(str); iss >> guess ; if (iss.eof() == false) std::cout << "its not int"; //cin >> guess;


3

I'm not 100% certain that I fully understand the thinking behind your question, but this should cover everything: ID3D11VertexShader *vs1; ID3D11VertexShader *vs2; device->CreateVertexShader (..., &vs1); device->CreateVertexShader (..., &vs2); We now have two vertex shaders, and this only needs to be done once, during startup. ...


3

No need to hook to HTML5 or native iOS/Android graphics functions when you have native OpenGL ES support on both platforms. On android binding native graphics Java functions to your C++ code would give you horrendous results. I think your problem can be solved with a little help from a friend... I would safely bet cocos2d-x does what you need. It is mainly ...


2

Since the customary language for ios is objective-c and android is java, you should add to your question that you need a kit that also supports C++ across those platforms. http://www.madewithmarmalade.com/ is one, it's probably stronger than what you're looking for and it's not free... but there is a trial version. I have not tried it personally, your ...


2

The physical centroid is used by the physics engine as a center of mass. The center of mass is not the same as the position of a composition of shapes. For instance, a body can have a transform position of (0, 0), and have it's shape's vertices for a polygon located around (10, 10). The shape vertices will be specified relative to the transform's location. ...


2

I did a test for that and the short answer is openGL didn't return any error. OpenGL documentation also states: glBindAttribLocation can be called before any vertex shader objects are bound to the specified program object. It is also permissible to bind a generic attribute index to an attribute variable name that is never used in a vertex shader. ...


2

You could go about this in different ways. Usually, you have a model's geometry centered around the origin (0,0,0), and to place it somewhere in the world you would use a world matrix, which offsets the entire model to a desired new position. This world matrix can reside in a constant buffer accessible to the vertex shader, where it would be combined with ...


2

I do not understand the problem. If you do not call the join(), they won't be waited for. You should call the join() only right before you absolutely need the data they produce. The other threads wont be stopped if you call join() on one of them. See the join() reference: http://www.cplusplus.com/reference/thread/thread/join/ VAOs are not shared in between ...


2

First off all To solve your problem, -if that was the only one-, unlike java, C++(MSVC) assigns 0xcccc for uninitialized variables in debug mode, you are not initializing it in the constructor, make sure to initialize all the variables in your class using the initialize list instead of assignment in the constructor, this has two advantage: It has to do ...


1

I have a few 2d implementations of dynamic spatial structures located here: https://github.com/ClickerMonkey/Steerio/tree/master/Java/src/org/magnos/steer/spatial As far as quad/octrees go, each iteration you check on everything in the database to see whether it has changed which node it belongs to. In my tree implementations I keep an entity in the ...


1

The SDL_Event type is a union. Only a single member of the union can be active at any point in time. Your crash is likely because you are accessing the key member when it isn't the active member. The proper way to do this is to check the event's type field before accessing the rest of it: if (e.type == SDL_KEYDOWN && e.key.keysym.sym...) In ...


1

The reason I cant store them as Block& is because that makes a copy of the Block when it is entered, Raw pointers should be avoided when possible. I'm not sure exactly what you mean by 'makes a copy'. Containers themselves can't store raw references. Possibly you are making a function accepting a ref but then putting them into a container with a ...


1

No one seems to have told you what the mistake in your first approach was: Calling join() right after each threads creation means your main thread waits for each thread before he creates the next one. Obviously this results in a sequential execution, not a parallel one. You need to maintain a list or something of the threads, and call join() on each of them ...


1

Re your first question - you could create your variable number of threads and store each one in a container (eg a vector). When you need all the data, you can do a join on each one - a for loop perhaps. See the answer to this question. It uses boost but the idea is similar.


1

First, your code should display time in nanoseconds as you asked. If you want more help on what is displayed, show us the output. Second: My question is, why do I get microseconds instead of nanoseconds ? If you are on Windows, using Visual Studio 2012 or 2013, there is a bug in the chrono standard library implementation that makes the high resolution ...


1

You can do it in the shader but it makes things really complicated. So the alternative i think of is to bake your geometry into one VBO/VAO for say... 16x16x16 boxes/voxels. If you need to change that data just change it and rebake the VBO/VAO for it. You need also some abstractions for the Shader Objects, a thing i call Buffer (Manages the VBO/VAO for the ...


1

You're using an int variable, and the input is going directly into that, so if the input is not an integer, C++ tries to convert it to one. The user, on the other hand, can enter any string (or char array, technically?), whether it's an integer, a decimal number, or not a number at all. For each of those three options: If the input is an integer, things ...


1

As far as I understood std::chrono you cant be sure to get a high resolution timer with std::steady_clock. So you might loose some accuracy on some system if the high resolution timer is not available as steady clock. I considered that too a while ago but than I read about steady clock and high resolution. I just can't find the reference at the moment. ...


1

Have you considered using the Qt framework? It has the UI and simple 2D graphics capability all in one package. Works on Windows, Apple, and phones.



Only top voted, non community-wiki answers of a minimum length are eligible