• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=ThePuska;38904583]This is more C than C++. [cpp]/* Prepend "n" to "list", return the new list. */ node *add_first(node *list, node *n) { n->next = list; return n; } /* Append "n" to "list", return the new list. */ node *add_last(node *list, node *n) { node *t = list; if (t) { while (t->next) t = t->next; t->next = n; return list; } else return n; }[/cpp][/QUOTE] I understand the node *n paramater, but what is the node *list parameter? And how come you can make a function with type node pointer? [editline]20th December 2012[/editline] Does it mean you can return a node pointer? [editline]20th December 2012[/editline] And is n the node you want to append/prepend, and list the first node in the list?
[QUOTE=Asgard;38906065]I understand the node *n paramater, but what is the node *list parameter? And how come you can make a function with type node pointer? [B]node *list is a pointer to the start of the list (just a node). The function returns a node* which serves as the new list start, you'd call it like this: list = add_first(list, new node()); then list would be the new start (since you just prepended something).[/B] [editline]20th December 2012[/editline] Does it mean you can return a node pointer? [B]Yes, you can return pointers.[/B] [editline]20th December 2012[/editline] And is n the node you want to append/prepend, and list the first node in the list? [B]Yes[/B] [/QUOTE]
Wouldn't head still point to the old first node in the list? [editline]20th December 2012[/editline] Wait, so list in your example is the same as head in mine? [editline]20th December 2012[/editline] I think I'm confusing myself :v [editline]20th December 2012[/editline] Yeah I got it now.
[QUOTE=robmaister12;38886657]You're transforming spaces. When you rotate a joint, all the child nodes have their spaces transformed by the joint's matrix. A rotation means that, say, the X axis, would be off at some weird angle relative to local space.[/QUOTE] So what would be the best way to get the current joints matrix? Something like this? [cpp] glm::mat4 Joint::GetMatrix() { glm::mat4 currTrans; currTrans = glm::translate(glm::mat4(1.0f), mTranslate) * glm::mat4_cast(mQuatRotate) * glm::scale(glm::mat4(1.0f), mScale); if(mParent != NULL) currTrans = mParent->GetMatrix() * currTrans; return currTrans; } [/cpp] and then use it as [cpp] glm::vec4 vecP4 = vect.GetJoint()->GetMatrix() * vect.pos; //vecP4 now holds the position of the vect with the joint forces applied [/cpp]
I want to understand how simplex noise works, where do I begin? Anyone know of any good and readable resources?
[url]http://webstaff.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf[/url]
What tutorial should I take for Lua? I'm a complete beginner to scripting.
I'm trying to start to create a platformer with c++ and sfml. I've just got a couple questions I would like answered. I know I need to regulate the game loop so that it doesn't run unpredictably. However I can't really figure out which timestep I want, I read the gaffersongames article about it. But that just leaves me with some issues. Such as, if I pick a fixed timestep, I will have a problem if somehow, the game runs slow, they'll be issues with game play degradation due to lag, ie skipping and what not or just running slow. And if I pick a semi-fixed timestep, then the game experience won't be the same without some serious calculation on how far a player should move and other things, and that would fuck up my class structure a lot trying to pass information into functions to do the predictions, or am I just thinking about it wrong somehow. Also, I'm trying to deal with sprite animation, I would love to hear about how some of you guys handle it. Like having separate actions having different animations, and dealing with timing of animations and what not. Cause my solutions is basically a class that wraps a map. I'm using the standard libraries map, which doesn't seem like a terribly fantastic data structure, but I'd rather not spend the time to write my own aha.
[QUOTE=Topgamer7;38915715]And if I pick a semi-fixed timestep, then the game experience won't be the same without some serious calculation on how far a player should move and other things, and that would fuck up my class structure a lot trying to pass information into functions to do the predictions, or am I just thinking about it wrong somehow. [/QUOTE] It's not that complex for most calculations. You should know the time since the last frame and the velocity of each entity.
[QUOTE=Muthenfrucheir;38915659]What tutorial should I take for Lua? I'm a complete beginner to scripting.[/QUOTE] [url]http://lua-users.org/wiki/TutorialDirectory[/url] [url]http://www.lua.org/pil/[/url] [editline]21st December 2012[/editline] [url]http://www.lua.org/manual/5.1/[/url]
So I'm trying to generate a filled sudoku field, any idea what I'm doing wrong here? In C#. It doesn't give any actual errors, it just returns false every time. Even after having my program loop through this 50.000.000 times. (Literally) [CODE] public bool gen(int spots) { Random Randomizer = new Random(); for (int i = 0; i < spots; i++) { int xRand,yRand; do { xRand = Randomizer.Next(1,10); yRand = Randomizer.Next(1,10); } while(n.numbers[yRand,xRand] != 0); // Set M of possible solutions byte[] M = {0,1,2,3,4,5,6,7,8,9}; // Remove used numbers in the vertical direction for(int a = 0; a <= 9; a++) M[n.numbers[a, xRand]] = 0; // Remove used numbers in the horizontal direction for(int b = 0; b <= 9; b++) M[n.numbers[yRand,b]] = 0; // Remove used numbers in the sub square. List<int> boxPos = c.findBox(yRand, xRand); List<int> boxTaken = c.BoxTaken(boxPos[0], boxPos[1]); for(int g = 0; g < boxTaken.Count; g++) { M[boxTaken[g]] = 0; } int cM = 0; // Calculate cardinality of M for(int d = 1; d < 10; d++) cM += M[d] == 0 ? 0 : 1; // Is there a number to use? if(cM > 0) { int e = 0; do { // Randomize number from the feasible set M e = Randomizer.Next(1, 10); } while(M[e] == 0); // Set number in Sudoku n.numbers[yRand, xRand] = (byte)e; } else { // Error return false; } } // Successfully generated a feasible set. return true; } [/CODE]
[QUOTE=Richy19;38906755]So what would be the best way to get the current joints matrix? Something like this? [cpp] glm::mat4 Joint::GetMatrix() { glm::mat4 currTrans; currTrans = glm::translate(glm::mat4(1.0f), mTranslate) * glm::mat4_cast(mQuatRotate) * glm::scale(glm::mat4(1.0f), mScale); if(mParent != NULL) currTrans = mParent->GetMatrix() * currTrans; return currTrans; } [/cpp] and then use it as [cpp] glm::vec4 vecP4 = vect.GetJoint()->GetMatrix() * vect.pos; //vecP4 now holds the position of the vect with the joint forces applied [/cpp][/QUOTE] Yep, that's basically how it works. All you have to do now is get the inverse base frame (essentially undoing the bone structure that the model is in originally) and you should have a more-or-less working system. You're probably going to get some very weird results as you're working out all the bugs. I can't really help you a whole lot with those since I haven't yet designed my own joint classes, but look at the IQM demos, all the math is there, you just have to move it around.
So trying to read in the iqm text attribute, problem is that file.read seems to stop reading in as soon as a null character is found, regardless of the specified size. [cpp] file.read((char*)&mTexts[0], sizeof(char) * mHeader.num_text); [/cpp]
Almost there, now just need too figure out why the head is flat [IMG]http://i.imgur.com/g8XYL.png[/IMG] [editline]21st December 2012[/editline] If anyone can find anything wrong with it: [url]http://pastebin.com/CAcp0s8B[/url] Im pretty sure its to do with the fact that im storing all verticies in one array and then applying an offset for each mesh in the model
I'm running a Mono-based server program on a Debian VPS, and I've got the server to start when the VPS boots. One of the things my server program does is generate some C# code that it compiles into an assembly stored in memory. The generated code is passed straight to CodeDomProvider.CompileAssemblyFromSource (not stored in a file or anything). This works fine as long as I start the program manually while the system is already running, but not when the program is started automatically after boot. I get this error: [code]Unhandled Exception: System.SystemException: Error running mcs: Cannot find the specified file at Mono.CSharp.CSharpCodeCompiler.CompileFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) at Mono.CSharp.CSharpCodeCompiler.CompileFromSourceBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] sources) at Mono.CSharp.CSharpCodeCompiler.CompileAssemblyFromSourceBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] sources) at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource (System.CodeDom.Compiler.CompilerParameters options, System.String[] sources)[/code] Looking at the stack trace it looks like Mono, when told to compile a string, saves the source in a temporary file and calls CompileFromFileBatch() on that new file. CompileFromFileBatch() then invokes mcs with the temporary file's location as input. For some reason, when I do this soon after system boot, it either can't find the temporary file(s), or can't find mcs (I can't tell which). I have very little experience with Linux, so does anyone who does know about running Mono apps on Debian have any ideas? I have the start / stop script in /etc/init.d and used update-rc.d to add the symbolic links to the /etc/rc#.d/ directories. Calling "/etc/init.d/<myscript> start" works fine, with no error. [editline]21st December 2012[/editline] Did some investigating, and the temporary files it creates certainly exist so for some reason it isn't finding mcs. Is there some reason why it wouldn't be able to find something in /usr/local/bin/ after startup? If so, is there a way I can trigger a script only after /usr/local/bin/ is available? [editline]21st December 2012[/editline] I've fixed it in a horrible, horrible way. I found the source in Mono, changed this line... [csharp]mcs.StartInfo.FileName="mcs";[/csharp] to: [csharp]mcs.StartInfo.FileName="/usr/local/bin/mcs";[/csharp] ...then rebuilt Mono. Any ideas of a better solution? Like a way of finding where mono is installed that is platform independent, instead of hard-coding it in?
[QUOTE=eternalflamez;38919953] [CODE] byte[] M = {0,1,2,3,4,5,6,7,8,9}; [/CODE][/QUOTE] I don't know C# and I'm new to programming, but if this is an array of the possible values for a thing in a square, 0 could be screwing it up because it's not used in Sudoku. [editline]21st December 2012[/editline] oh, reread your code, I see now
Okay well I have officially decided I can't do this by myself, so I'll post here. I'm trying to figure out the Unreal Development Kit, but I keep hitting arbitrary roadblocks. In my opinion, the engine isn't documented that well (the beginning stuff isn't nearly comprehensive enough, and the technical stuff isn't nearly explanatory enough, I feel) and Google searches give me results that are not that relevant to what I am trying to achieve. [b]My end goal[/b] is to use the UDK to build a total conversion (aka I do not use any UT elements that come with the UDK) stand-alone game on the Unreal engine. [b]My current goal[/b] is to figure out how to give the player a weapon on start. At the moment, I am deriving UT, just so I have some weapons I know that works. However, I cannot figure out, for the life of me, how to use Kismet to give the player a rocket launcher on start-up (player spawns with Link Gun by default). For that matter, I can't figure out how the player is given their default loadout at all. Once I have that figured out, I intend to instead work on building some weapons that inherit from UDKBase (to get out of deriving UT, so the game is stand-alone), and go from there. But I can't very well work on making my own weapons, when I can't even figure out how to give players pre-existing weapons. Beyond all that, I need to figure out how exactly the game start-up works in general, but I think I can manage that, once I figure these things out. Does anyone think they can help me? I've spent over 2 hours now trying to figure this out.
[QUOTE=Gmod4ever;38935696]Okay well I have officially decided I can't do this by myself, so I'll post here. I'm trying to figure out the Unreal Development Kit, but I keep hitting arbitrary roadblocks. In my opinion, the engine isn't documented that well (the beginning stuff isn't nearly comprehensive enough, and the technical stuff isn't nearly explanatory enough, I feel) and Google searches give me results that are not that relevant to what I am trying to achieve. [b]My end goal[/b] is to use the UDK to build a total conversion (aka I do not use any UT elements that come with the UDK) stand-alone game on the Unreal engine. [b]My current goal[/b] is to figure out how to give the player a weapon on start. At the moment, I am deriving UT, just so I have some weapons I know that works. However, I cannot figure out, for the life of me, how to use Kismet to give the player a rocket launcher on start-up (player spawns with Link Gun by default). For that matter, I can't figure out how the player is given their default loadout at all. Once I have that figured out, I intend to instead work on building some weapons that inherit from UDKBase (to get out of deriving UT, so the game is stand-alone), and go from there. But I can't very well work on making my own weapons, when I can't even figure out how to give players pre-existing weapons. Beyond all that, I need to figure out how exactly the game start-up works in general, but I think I can manage that, once I figure these things out. Does anyone think they can help me? I've spent over 2 hours now trying to figure this out.[/QUOTE] Ok, It's been about 6 months since I touched kismet so I hope I don't miss anything but this might work: 1 - Go to View-> world properties (and under world info) select "no default inventory for player" 2 - Open Kismet 3 - Create a new "Level Loaded" event (New Event -> Level loaded) 4 - Create a delay (New Action -> Misc -> Delay) 5 - Create a new "Give Inventory" event (New Action -> Pawn -> Give Inventory) 6 - Create a new "Player" target (New Variable -> Player -> Player) 7 - Link the following: - Loaded and Visible to Start (And set Duration on the Delay to 1) - Finished to In (and Tick "Clear Existing" and "Force Replace") In those same properties click on the "add new item" button next to "Inventory List" and Select the weapon you want them to have - Target to Player [img]http://i.imgur.com/umC53.png[/img] Hopefully that will work. Let me know if it doesn't work and I will try to figure out why
I understand the difference between passing by value and passing by reference in C++. However, when is it appropriate to pass by value, and when by reference?
[QUOTE=Asgard;38935983]I understand the difference between passing by value and passing by reference. However, when is it appropriate to pass by value, and when by reference?[/QUOTE] Pass by reference if you need to modify the data from inside the function (or, in some languages, pass by constant reference if you're going to be dealing with a lot of overhead copying the data across), otherwise pass by value. That's the simplest rule I can think of, it doesn't cover all cases by any means but it should serve as a good rule of thumb.
[QUOTE=Asgard;38935983]I understand the difference between passing by value and passing by reference in C++. However, when is it appropriate to pass by value, and when by reference?[/QUOTE] You should pass by reference when the function needs to modify the parameter or copying the value is expensive.
[QUOTE=LonelyTimeLord;38935912]Ok, It's been about 6 months since I touched kismet so I hope I don't miss anything but this might work: ... [b]In those same properties click on the "add new item" button next to "Inventory List" and Select the weapon you want them to have[/b] ... Hopefully that will work. Let me know if it doesn't work and I will try to figure out why[/QUOTE] Thank you. This was it. It took me nearly three minutes of alternately staring at this sentence and playing around with Kismet, before I finally figured out where this properties thing was and how to use it. This was the step I was missing. Thank you [b]very[/b] much, mate! I am assuming from your statement of not touching Kismet for a while that you are fairly competent with the UDK now (and thusly don't need to use Kismet). Would you mind if I added you to Steam Friends? I am going to have many more questions as I get through the learning curve of this particular engine and how it works (difference between building something from scratch and using something someone else made is that you have to figure out how to make things you make work with things they made :v:), and I find it a lot easier picking other peoples' brain for trivially simple things than trying to formulate a search query and then having to sift through Google results. I am hoping to not be too much a nuisance after the first few days. I'm pretty confident that my OO (and non-OO for that matter) programming experience will be able to help me, once I've got my feet grounded.
[QUOTE=Asgard;38935983]I understand the difference between passing by value and passing by reference in C++. However, when is it appropriate to pass by value, and when by reference?[/QUOTE] What I was thought, (mostly by people on the forum) is pass primitives by value, pass anything else by reference. If your going to need to modify it then just pass it as a normal reference, if your not going to modify it pass it as a const reference to make sure you dont change anything by mistake
I'm trying to make a simple HTTP server in Python: [code] ... from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer ... server = HTTPServer(('', 8080), BaseHTTPRequestHandler) print 'Started httpserver on port 8080' running = True while running: server.handle_request() ... [/code] Problem is I want to do other stuff while waiting for a request, and server.handle_request() is blocking until it gets a request. Is there a way to [I]check[/I] for a request instead of waiting for one?
I have an enum which respresents the positions of registers in an array of registers for an emulator of a fictitious microprocessor. [cpp] #define NUM_REG 5 ... typedef enum registers { IP, // Instruction Pointer IS, // Instruction R0, // General Purpose Register Zero R1, // General Purpose Register One SW // Swap register } t_reg; ... typedef struct emulator { // Operation code t_ops op; // Status code t_status status; // Actual program as array of bytes int prog[MAX_BYTE]; // Registers as array of bytes int reg[NUM_REG]; // Total number of digits output int out_len; } t_emul; [/cpp] My question is how to deal with determining the length of an enum. In this implementation I use the preprocessor to define the max value in a byte ( MAX_BYTE ), and so I naturally used a #define to set the number of registers there are. I just decided to add a new register, and realized this means I have to add the register to the enum but also increment the #define by one. Instead I would like to determine the number of registers automatically. -snip- Neither of the methods I thought of work because I end up declaring an array with a variable for the dimension. So my question now boils down to: is it possible to determine the number of elements in an enum from within a preprocessor directive?
[QUOTE=MakeR;38936010]You should pass by reference when the function needs to modify the parameter or copying the value is expensive.[/QUOTE] Yeah, like passing an entire image to a function through a void pointer, copying it, then not freeing the memory... that was a fun leak to debug...
[QUOTE=Rayjingstorm;38940431]I have an enum which respresents the positions of registers in an array of registers for an emulator of a fictitious microprocessor. [cpp] #define NUM_REG 5 ... typedef enum registers { IP, // Instruction Pointer IS, // Instruction R0, // General Purpose Register Zero R1, // General Purpose Register One SW // Swap register } t_reg; ... typedef struct emulator { // Operation code t_ops op; // Status code t_status status; // Actual program as array of bytes int prog[MAX_BYTE]; // Registers as array of bytes int reg[NUM_REG]; // Total number of digits output int out_len; } t_emul; [/cpp] My question is how to deal with determining the length of an enum. In this implementation I use the preprocessor to define the max value in a byte ( MAX_BYTE ), and so I naturally used a #define to set the number of registers there are. I just decided to add a new register, and realized this means I have to add the register to the enum but also increment the #define by one. Instead I would like to determine the number of registers automatically. -snip- Neither of the methods I thought of work because I end up declaring an array with a variable for the dimension. So my question now boils down to: is it possible to determine the number of elements in an enum from within a preprocessor directive?[/QUOTE] From what I've seen, this problem is often solved by adding an extra variable to the enum named something like "last", that takes the value of the previous enum like so: [cpp] typedef enum registers { IP, // Instruction Pointer IS, // Instruction R0, // General Purpose Register Zero R1, // General Purpose Register One SW, // Swap register LAST = SW } t_reg; [/cpp] That way, when you want to add a register, you just add it after SW and change the value of LAST to that of the new register. This way you also have the advantage of avoiding name collisions with other defines.
[QUOTE=Dr Magnusson;38942385]From what I've seen, this problem is often solved by adding an extra variable to the enum named something like "last", that takes the value of the previous enum like so: [cpp] typedef enum registers { IP, // Instruction Pointer IS, // Instruction R0, // General Purpose Register Zero R1, // General Purpose Register One SW, // Swap register LAST = SW } t_reg; [/cpp] That way, when you want to add a register, you just add it after SW and change the value of LAST to that of the new register. This way you also have the advantage of avoiding name collisions with other defines.[/QUOTE] Actually, you should let LAST just get the next value as usual (I usually call it COUNT), since enums are zero-indexed by default. So if you create an array with the size of LAST you would get one size too small.
So, I'm trying to write a button class for the menus of my game in C++ and I have that onClick() function. Now, I want to parse another function as parameter to the onClick() function, so the onClick() function can run it. I want to do that, because I might have different buttons, which all have to run different functions when they are clicked.( Setting Volume, changing gamestate, sending message, etc. ) Example of what I mean: [CODE] Button startGameButton; GameState playState; void changeState( GameState state ); if ( the mouse position is on the button & mouse button 1 is pressed ) startGameButton.onClick( changeState( playState ) ); [/CODE] [CODE] Button sendMessageButton; void sendMessage( const std::string message ); if ( the mouse position is on the button & mouse button 1 is pressed ) sendMessageButton.onClick( sendMessage( "Hi!" ) ); [/CODE] I read something about function pointers, but it seems like you must predefine what parameters the function will have, but I might want to parse function that have completely different parameters. Is there a way around it or is there any other solution to this problem?
Thank you very much Dr Mag and Z_guy! Although it doesn't save a whole lot of editing, it is nice to be able to add new registers/operations without making changes in more than one place.
Sorry, you need to Log In to post a reply to this thread.