• What do you need help with? V. 3.0
    4,884 replies, posted
C++ Im looking to do something along the lines of have a template, which takes an object and a member function as parameters, and then calls that member function of that object. Or some equivalent, I'm not sure how the syntax even begins to work out as I don't normally mess with templates quite this much :v:
[QUOTE=Icedshot;30379164]C++ Im looking to do something along the lines of have a template, which takes an object and a member function as parameters, and then calls that member function of that object. Or some equivalent, I'm not sure how the syntax even begins to work out as I don't normally mess with templates quite this much :v:[/QUOTE] [cpp] template<typename T> void foo(T& t) { t.bar(); } [/cpp] edit: I misread and missed the second requirement. What type do you imagine your member function parameter being, exactly? Will it always be the same member function?
Does anyone have a good recommendation for a C# or Assembly book
[QUOTE=Doritos_Man;30381688]Does anyone have a good recommendation for a C# or Assembly book[/QUOTE] C# in Depth and the Intel manuals
[QUOTE=Tangara;30381868]C# in Depth and the Intel manuals[/QUOTE] Can I get a link to the Intel manuals
[url]http://www.intel.com/products/processor/manuals/[/url]
[QUOTE=jA_cOp;30381259][cpp] template<typename T> void foo(T& t) { t.bar(); } [/cpp] edit: I misread and missed the second requirement. What type do you imagine your member function parameter being, exactly? Will it always be the same member function?[/QUOTE] Not entirely sure what you mean, so ill give you a practical example of what im trying to achieve [cpp]Function=templatedfunction<sfml_input, sfml_input.IsMouseButtonDown>;[/cpp] then the main body of the templated function would be (incorrectly) [cpp]return sfml_input.IsMouseButtonDown()[/cpp] Except, i want it to be using the member function i passed rather than specifically using IsMouseButtonDown like itll do here
[QUOTE=Icedshot;30387335]Not entirely sure what you mean, so ill give you a practical example of what im trying to achieve [cpp]Function=templatedfunction<sfml_input, sfml_input.IsMouseButtonDown>;[/cpp] then the main body of the templated function would be (incorrectly) [cpp]return sfml_input.IsMouseButtonDown()[/cpp] Except, i want it to be using the member function i passed rather than specifically using IsMouseButtonDown like itll do here[/QUOTE] I don't quite see the use for this, but here it is: [cpp] template<typename T, typename R> R callMember(T& t, R (T::*f)()) { return (t.*f)(); } void example(sf::Input& input) { bool isDown = callMember(input, &sf::Input::IsMouseButtonDown); } [/cpp] There is a big problem with your (and conversely, my) example, though: IsMouseButtonDown expects a parameter. This is a solvable problem in a couple of different ways. Without C++0x, you need an overload for every amount of parameters you want to support (including the above version for no parameters). Example supporting 0 or 1 parameters: [cpp] template<typename T, typename R> R callMember(T& t, R (T::*f)()) { return (t.*f)(); } template<typename T, typename R, typename Arg1> R callMember(T& t, R (T::*f)(Arg1), Arg1 arg1) { return (t.*f)(arg1); } void example(sf::Input& input) { bool isDown = callMember(input, &sf::Input::IsMouseButtonDown, sf::Mouse::Left); } [/cpp] I will post the generic C++0x solution once I have tested it. However, I don't see how this kind of function is very useful. What are you trying to do? There could be a better way. edit: In C++0x, you can support any number of parameters with a single function like this: [cpp] template<typename T, typename R, typename... Args> R callMember(T& t, R (T::*f)(Args...), Args&&... args) { return (t.*f)(std::forward<Args>(args)...); } [/cpp]
[QUOTE=jA_cOp;30387595]-snip-[/QUOTE] Thanks, thats pretty much exactly what im looking for What im trying to do is write an application for a device where i don't know how input or output will be handled etc. I thought a solution to this would be to create a function pointer to templated functions, with the arguments of the templates being an object and the member function for getting the piece of input from the object, so that its very easy to change based on how the input actually works Plus, its always interesting to know how the syntax for these things actually works :v:
[QUOTE=Icedshot;30387742]Thanks, thats pretty much exactly what im looking for What im trying to do is write an application for a device where i don't know how input or output will be handled etc. I thought a solution to this would be to create a function pointer to templated functions, with the arguments of the templates being an object, and the member function for getting the piece of input from the object, so that its very easy to change based on how the input actually works Plus, its always interesting to know how the syntax for these things actually works :v:[/QUOTE] It is actually possible to abstract with templates here, but it would be a lot easier if you just used interfaces.
I was about to say, why not just write an interface to handle your input stuff or whatever, so you can just derive from that to create input interfaces for different input systems.
[QUOTE=Chris220;30387810]I was about to say, why not just write an interface to handle your input stuff or whatever, so you can just derive from that to create input interfaces for different input systems.[/QUOTE] [QUOTE=jA_cOp;30387801]It is actually possible to abstract with templates here, but it would be a lot easier if you just used interfaces.[/QUOTE] Im afraid at this point, i have to admit that i've never actually heard of an interface Edit: Does anyone have a link to an explanation? Would probably be useful to know about
[QUOTE=Icedshot;30387823]Im afraid at this point, i have to admit that i've never actually heard of an interface[/QUOTE] [cpp] // input.hpp // The input interface class Input { public: virtual bool leftMouseButtonDown() = 0; }; //SFML input implementation example: #include <input.hpp> #include <SFML/Window.hpp> //or wherever sf::Input is accessible from class SfmlInput : public Input { private: sf::Input& input; public: SfmlInput(sf::Input& input) : input(input) {} bool leftMouseButtonDown() { return input.IsMouseButtonDown(sf::Mouse::Left); } }; //Then later on... int main() { sf::Window window(...); SfmlInput input(window.GetInput()); ... doStuffWithInput(input); ... } void doStuffWithInput(Input& input) { // knows nothing about sf::Input! if(input.leftMouseButtonDown()) { ... } } [/cpp] The SfmlInput class wraps sf::Input and [i]implements[/i] the Input interface. The type "SfmlInput" is only referenced once in the entire program: when it's created (this is obviously not a requirement when using the interface pattern, the point is that it's rarely referenced). All other references are to the abstract class Input. Thus, SfmlInput can be easily replaced with another kind of input implementation. You would add more member functions to Input as the requirements of your application grow. Note that in my example you could also abstract the sf::Mouse::Button enum in some way if you wanted to use an API similar to SFML, but don't bother doing it unless it's really worth your time.
I'm using PDCurses to display some text (the graphics of the game), what can I use for input? getch() pauses the game, which I do not want. I'm ok with using other libraries, but I would like to keep it a small as possible.
[QUOTE=jA_cOp;30387595][cpp] template<typename T, typename R, typename... Args> R callMember(T& t, R (T::*f)(Args...), Args&&... args) { return (t.*f)(args...); } [/cpp][/QUOTE] You probably mean [cpp]return (t.*f)(std::forward<Args>(args)...);[/cpp] [QUOTE=Dryvnt;30388155]I'm using PDCurses to display some text (the graphics of the game), what can I use for input? getch() pauses the game, which I do not want. I'm ok with using other libraries, but I would like to keep it a small as possible.[/QUOTE] Use the nodelay or timeout, which are probably available from PDCurses.
[QUOTE=jA_cOp;30387962]-snip-[/QUOTE] Thanks, though thats pretty much what i was doing originally before i decided to screw around with templates :v: Edit: Well, now it works like this [cpp]GetX=BindFunction<sf::Input, int, &sf::Input::GetMouseX, &Input>;[/cpp] What you gave me was different, but very helpful to what i was trying to achieve so :buddy:
Anyone know of a way to do this sort of stuff better? [csharp] public static Thing GetThing(int name) { for(int i= 0; i< Box.boxes.Length; i++) { for(int j= 0; j< Box.boxes[i].Length; j++) { for(int k= 0; k< Box.boxes[i][j].Length; k++) { foreach(Thing thing in Box.boxes[i][j][k].things) if(thing.name== name) return thing; } } } return null; } public static Box GetBox(Thing thing_) { for(int i= 0; i< Box.boxes.Length; i++) { for(int j= 0; j< Box.boxes[i].Length; j++) { for(int k= 0; k< Box.boxes[i][j].Length; k++) { foreach(Thing thing in Box.boxes[i][j][k].things) if(thing== thing_) return Box.boxes[i][j][k]; } } } return null; } public static Box GetBox(int name) { for(int i= 0; i< Box.boxes.Length; i++) { for(int j= 0; j< Box.boxes[i].Length; j++) { for(int k= 0; k< Box.boxes[i][j].Length; k++) { foreach(Thing thing in Box.boxes[i][j][k].things) if(thing.name== name) return Box.boxes[i][j][k]; } } } return null; } public static Vector3 GetOffset(Box box) { for(int i= 0; i< Box.boxes.Length; i++) { for(int j= 0; j< Box.boxes[i].Length; j++) { for(int k= 0; k< Box.boxes[i][j].Length; k++) { if(Box.boxes[i][j][k]== box) return new Vector3(i, j, k); } } } return Vector3.Zero; } public static Vector3 GetOffset(Thing thing_) { for(int i= 0; i< Box.boxes.Length; i++) { for(int j= 0; j< Box.boxes[i].Length; j++) { for(int k= 0; k< Box.boxes[i][j].Length; k++) { foreach(Thing thing in Box.boxes[i][j][k].things) if(thing== thing_) return new Vector3(i, j, k); } } } return Vector3.Zero; } [/csharp] I had toyed around with the idea when I first made the class that handles this to simply keep all the elements in a 1 dimensional array, but I'm unsure whether it would be a smart move to convert. It would be better if I could just have some sort of function template that handled the first part and allowed me to just write the parts that change.
What does that thing even do :ohdear:
How would I go about turning off collision when a player collides with a team mate in hl2? ( c++)
[QUOTE=esalaka;30394289]What does that thing even do :ohdear:[/QUOTE] They all go through the list of Things for each box in a 3 dimensional array of boxes.
it would probably be cleaner if you made them foreach loops, but it'll still be really messy. Consider reorganizing or redesigning your current system if you feel it's unorganized enough to affect performance.
Is there any way to get OpenGL to use bilinear interpolation when interpolating values to give to the fragment shader? Specifically, when using quads. At the moment there is a noticeable diagonal line through the quad where the quad has been split into two triangles. [img]http://i55.tinypic.com/mhyd54.png[/img] I currently have the square on the left, I would like the square on the right.
[QUOTE=Robert64;30407251]Is there any way to get OpenGL to use bilinear interpolation when interpolating values to give to the fragment shader? Specifically, when using quads. At the moment there is a noticeable diagonal line through the quad where the quad has been split into two triangles.[/QUOTE] I think if you divide the Quad up into 4 triangles sharing a point in the middle you can calculate the middle color yourself and that should allow the quad to be correctly interpolated.
[QUOTE=bean_xp;30407292]I think if you divide the Quad up into 4 triangles sharing a point in the middle you can calculate the middle color yourself and that should allow the quad to be correctly interpolated.[/QUOTE] I tried that before, all I got were more lines that stand out although they stood out slightly less. I assumed OpenGL would have bilinear interpolation for quads somewhere, seems like an odd thing to omit.
[QUOTE=Robert64;30407353]I tried that before, all I got were more lines that stand out although they stood out slightly less. I assumed OpenGL would have bilinear interpolation for quads somewhere, seems like an odd thing to omit.[/QUOTE] I think Quad rendering is left to implementation detail by OpenGL so most drivers will render the Quad as 2 triangles. DirectX actually doesn't support Quads at all, which may explain why the option would be missing from OpenGL. I'm not sure why the 4 triangle approach is still presenting artifacts though, it should give a big improvement over the obvious diagonals. Another way you could attempt would be loading the color values into a texture and sampling it per-pixel as texture sampling performs bilinear interpolation.
Maybe this helps [url]http://i56.tinypic.com/316p578.png[/url] It's part of the OpenGL reference card [url]http://www.khronos.org/files/opengl-quick-reference-card.pdf[/url]
I've got a simple program that my teacher has to take a look at. He isn't a programmer and needs it in an exe. However, I can't seem to figure out how to get Eclipse to compile it into an exe.
[QUOTE=CommanderPT;30409049]I've got a simple program that my teacher has to take a look at. He isn't a programmer and needs it in an exe. However, I can't seem to figure out how to get Eclipse to compile it into an exe.[/QUOTE] Have a look at [url]http://www.excelsior-usa.com/articles/java-to-exe.html#aot[/url]
[QUOTE=RyanDv3;30374504]Is it possible in C# to call the parent constructor within the body of the child constructor, or does it have to appear right after the child constructor declaration? Right now the child class's constructor takes a filename, from which it reads information. The problem is that the parent constructor's variables are readonly so they need to be set in a parent constructor, and I don't have the info it needs until I've finished reading the file. Is my only option creating a static Load(String filename) function that calls the constructor with all the data?[/QUOTE] Create a protected method in your parent file, you initialize all your things in there, you call it from your parent's constructor and your child's constructor. [b]Edit:[/b] And that is how you forgot to check the last page, oh well, perhaps it might still be useful
Could someone possibly explain how matrices work, simply? I'm trying to get DebugView for Farseer physics working, but it says it needs a ref matrix or something like that. I unserstand that a matrix is a 2d table of numbers like so [code] [1 2 3 4] [4 3 2 1] [1 2 4 3] [3 4 2 1] [/code] But how does it relate to what I'm trying to do?
Sorry, you need to Log In to post a reply to this thread.