|
brian posted:I'm having trouble using a really old fixed point library in VC++ 2008, any time I use the following two ASM based functions I get linking errors and I have no idea to fix it, is it a compiler flag I have to enable? I really need the fixed multiplication and division to be as fast as possible, it's for music generation on the GP2X which doesn't have an FPU. Wrong question. You're trying to compile x86 asm for an ARM CPU. Not going to happen.
|
# ? May 8, 2009 16:05 |
|
|
# ? May 17, 2024 11:56 |
|
Bugger, this is really annoying, I tried another fixed library but it was slower than using floats, although that is probably just due to the sine function it has being slower than if I used a sine table.
|
# ? May 8, 2009 16:12 |
|
brian posted:Bugger, this is really annoying, I tried another fixed library but it was slower than using floats, although that is probably just due to the sine function it has being slower than if I used a sine table. Then why not just write your own sin function that uses a table?
|
# ? May 8, 2009 17:36 |
|
Anyone know of a portable ANSI C XML generation (not parsing) library? I don't think writing some code to spit out XML as I walk through my data will be that hard, but I'd rather not reinvent the wheel if I don't have to. This is for an 8051 derivative microcontroller, so the perfect library would have a tiny memory footprint. Even if I can't find exactly what I want, I'm still interested in checking out how some other people handled this. e: I figured out that -"C#" and -"C++" are my friends when doing a google search for ansi C stuff. I found genx. I'd still love to hear about any others, though. taqueso fucked around with this message at 18:47 on May 8, 2009 |
# ? May 8, 2009 18:45 |
|
Zakalwe posted:Wrong question. You're trying to compile x86 asm for an ARM CPU. Not going to happen. These 2 look portable to C, albeit I am not sure about the idiv --- it's a 64-bit over 32-bit division, isn't it?
|
# ? May 8, 2009 18:51 |
|
I am doing something really stupid with fstream but cannot figure out what. I want to open a file, read all the contents, and start appending to it.code:
|
# ? May 8, 2009 21:51 |
|
OddObserver posted:These 2 look portable to C, albeit I am not sure about the idiv --- it's a 64-bit over 32-bit division, isn't it? Yeah, but the code posted doesn't use the DX register (the reminder)
|
# ? May 8, 2009 22:26 |
|
Chuu posted:I am doing something really stupid with fstream but cannot figure out what. I want to open a file, read all the contents, and start appending to it. I don't think ios::app is supposed to be used for input streams (even input-output streams). Try removing that and see if it still fails.
|
# ? May 8, 2009 22:29 |
|
Chuu posted:
You can use std::ios::in instead of ios_base to save some typing. You don't need ate or app or seekg() for this problem, just use ios::in | ios::out. After the end of your while loop the stream's eof flag will be set. If you want to write to the file you need to clear that flag with m_file.clear(); You don't need to construct a string to stream "hi" to the file, just do m_file << "hi" << ... You don't need endl and flush as the former will also flush the stream for you. Instead of if (!m_file.open ()) you can simply use if (!m_file). To help with testing assumptions you can use assert(). So instead of doing code:
code:
|
# ? May 8, 2009 22:31 |
|
Chuu posted:I am doing something really stupid with fstream but cannot figure out what. I want to open a file, read all the contents, and start appending to it. Try std::string("hi").c_str() or just "hi". There is no implicit conversion from std::string to char*.
|
# ? May 8, 2009 22:34 |
|
Lexical Unit posted:After the end of your while loop the stream's eof flag will be set. If you want to write to the file you need to clear that flag with [fixed]m_file.clear(); Thanks for the advice in this thread. This was the issue.
|
# ? May 8, 2009 22:44 |
|
What's the best way right now to develop Windows GUI applications in C++? I'd like to have a GUI builder similar to Visual C++ that abstracts away all the low-level stuff, but without spending thousands of dollars... Is Code::Blocks with wxWidgets any good?
|
# ? May 10, 2009 18:15 |
|
Fehler posted:What's the best way right now to develop Windows GUI applications in C++? I'd like to have a GUI builder similar to Visual C++ that abstracts away all the low-level stuff, but without spending thousands of dollars... Try http://www.qtsoftware.com/products/platform/qt-for-windows I personally never write GUI apps, but my friend who's a great C++ programmer swears by it. It's also cross-platform, so if you decide to target Mac OSX or Linux at least the GUI will port quite easily.
|
# ? May 10, 2009 18:22 |
|
Fehler posted:What's the best way right now to develop Windows GUI applications in C++? I'd like to have a GUI builder similar to Visual C++ that abstracts away all the low-level stuff, but without spending thousands of dollars... Why would you have to spend thousands of dollars? Visual C++ Express is free.
|
# ? May 10, 2009 18:32 |
|
Zakalwe posted:Try http://www.qtsoftware.com/products/platform/qt-for-windows Avenging Dentist posted:Why would you have to spend thousands of dollars? Visual C++ Express is free.
|
# ? May 10, 2009 18:55 |
|
Fehler posted:Yeah, but isn't that pretty limited in its functionality and/or has some weird license restrictions? (also, this is where I tell you that Win32 C++ development is infuriating and you really want to use C# instead )
|
# ? May 10, 2009 19:01 |
|
Are you a student? You can get Professional Edition for free from Microsoft's DreamSpark.
|
# ? May 10, 2009 19:12 |
|
Mustach posted:Are you a student? You can get Professional Edition for free from Microsoft's DreamSpark. This is awesome.
|
# ? May 11, 2009 03:48 |
|
Hey guys, I'm writing a program in C that takes in options, and input file and (sometimes) an output file from the command line. I'm using getopt as it says to in the spec. I can process the options (like -f, -e etc) okay but I'm having trouble with how to handle the input and output files. The example command line input is: program -e [-f] [-c] [-o outputfile] inputfile (the [] denote optional inputs). Can anyone shed any light?
|
# ? May 11, 2009 10:41 |
|
CaptainMcArrr posted:Hey guys, I'm writing a program in C that takes in options, and input file and (sometimes) an output file from the command line. I'm using getopt as it says to in the spec. I can process the options (like -f, -e etc) okay but I'm having trouble with how to handle the input and output files. The example command line input is: code:
code:
code:
code:
ChiralCondensate fucked around with this message at 12:46 on May 11, 2009 |
# ? May 11, 2009 12:40 |
|
ChiralCondensate posted:Helpfulness Oh man, thanks. That was really helpful, you have no idea how much happier I am now.
|
# ? May 11, 2009 14:19 |
|
What's the best way to impliment an undo function for a turn based strategy game? It would be for options like, create unit, move unit, etc. I think I only need it one undo deep. Currently I'm thinking I'm going to have to make undo functions for every option/function I want to undo and then keep information on each function that is performed that could be undone. This method doesn't seem that elegent, easy or quick. Also I'll have to edit the undo function everytime I edit the normal function. Edit: suppose to be in the general programming questions thread, not this one.
|
# ? May 11, 2009 17:36 |
|
Keep a track of either all the gamestates or the changes at each step, and when a player chooses to undo, go back in the array/vector/whatever one step
|
# ? May 11, 2009 18:08 |
|
Unparagoned posted:Currently I'm thinking I'm going to have to make undo functions for every option/function I want to undo and then keep information on each function that is performed that could be undone.
|
# ? May 11, 2009 19:21 |
|
ultra-inquisitor posted:There's no convenient relationship between all the 'do's and 'undo's you'll be performing. There certainly is: a class. I will leave it as an exercise to the reader to design an interface that allows for "do" and "undo" operations.
|
# ? May 11, 2009 19:29 |
|
Avenging Dentist posted:There certainly is: a class. I will leave it as an exercise to the reader to design an interface that allows for "do" and "undo" operations. newsomnuke fucked around with this message at 20:02 on May 11, 2009 |
# ? May 11, 2009 19:40 |
|
Avenging Dentist posted:There certainly is: a class. I will leave it as an exercise to the reader to design an interface that allows for "do" and "undo" operations. A quick google, suggests you mean something like making a copy of everything in the previous state. Is that right?
|
# ? May 11, 2009 19:41 |
|
Unparagoned posted:A quick google, suggests you mean something like making a copy of everything in the previous state. Is that right? What? No (though that's an acceptable solution anyway). I mean "write specific do/undo code for all operations (it's easy) and let the interfaces do the work for you to determine what (if anything) you need to undo".
|
# ? May 11, 2009 20:00 |
|
Unparagoned posted:A quick google, suggests you mean something like making a copy of everything in the previous state. Is that right? There's two approaches to this. If your total game state can be stored very easily and concisely, say in a single structure, then one way is to simply push a copy of the total game state on to a stack after every action. Then "undo" has nothing to do with any particular action, you simply pop the last game state off and restore it wholesale. But usually storing a representation of program state takes up too much space, or involves outside resources, making it too complicated for the above method. Then a better way is probably to use Actions. In this case, everything that can be done in the game has to have an associated Action class. The class knows how to "do" the action, but also, knows how to "undo" the action, relative to whatever the current state happens to be. Instead of pushing game state on to a stack, you push Action objects on to a stack. And when you want to undo the last action, you pop off the last Action object and invoke its "undo" method.
|
# ? May 11, 2009 20:01 |
|
Avenging Dentist posted:What? No (though that's an acceptable solution anyway). I mean "write specific do/undo code for all operations (it's easy) and let the interfaces do the work for you to determine what (if anything) you need to undo". I don't understand Avenging Dentist posted:I mean "write specific do/undo code for all operations (it's easy) BigRedDot posted:Then a better way is probably to use Actions. In this case, everything that can be done in the game has to have an associated Action class. The class knows how to "do" the action, but also, knows how to "undo" the action, relative to whatever the current state happens to be. Instead of pushing game state on to a stack, you push Action objects on to a stack. And when you want to undo the last action, you pop off the last Action object and invoke its "undo" method. I think I kind of get this but let me make sure. Sorry for the poor c++ code below, it's just to get this action idea. code:
|
# ? May 11, 2009 20:33 |
|
Unparagoned posted:What do you mean it's easy. Either its specific(I class this as "not easy" in this contex), or is there some kind trick you are trying to get at? How is writing a few lines of code "hard"? Seriously, unless you're making all your actions ridiculously complex, we're talking about 5-10 lines of straightforward code per action type, tops. Unparagoned posted:I think I kind of get this but let me make sure. Sorry for the poor c++ code below, it's just to get this action idea. Why would you use RAII for action objects? That is just asking for trouble (like when you purge old actions once they're too old to undo). Read what he said again: quote:And when you want to undo the last action, you pop off the last Action object and invoke its "undo" method.
|
# ? May 11, 2009 20:39 |
|
Not quite. Something more like this:code:
You should probably think some about what to do when "Undo"-ing is not possble for whatever reason. You can also decouple your game logic from your do/undo system. MoveAction would then just hold a reference to some model object that actually does all the state updates, instead of doing it itself. Probably overkill for your needs. Edit: "pubic Action" probably belongs in E/N BigRedDot fucked around with this message at 21:04 on May 11, 2009 |
# ? May 11, 2009 20:50 |
|
Avenging Dentist posted:Why would you use RAII for action objects? That is just asking for trouble (like when you purge old actions once they're too old to undo). Read what he said again: Thanks. So do I just have a class and have an undo method in the class. Is it ok to have the do action in the init of the class? Avenging Dentist posted:How is writing a few lines of code "hard"? Seriously, unless you're making all your actions ridiculously complex, we're talking about 5-10 lines of straightforward code per action type, tops. Sorry I got a bit confused. Here is what I though Me: I would have to write undo functions for each function and update it every time I change the function. ultra-inquisitor: yep you have to, there is no convenient way of doing it. Avenging Dentist: There is a convenient way to do it... So I thought it was all about writing uniquie undo functions. So when you said easy, I though your were talking about some easier way of finding or writing an undo function. Unparagoned posted:Currently I'm thinking I'm going to have to make undo functions for every option/function I want to undo and then keep information on each function that is performed that could be undone. ultra-inquisitor posted:It's really the only way. For instance, a 'move' action may update the pathfinding database, and this would have to be reset. A 'create' action would allocate memory, and this would have to be deleted. There's no convenient relationship between all the 'do's and 'undo's you'll be performing. Avenging Dentist posted:There certainly is: a class. I will leave it as an exercise to the reader to design an interface that allows for "do" and "undo" operations.
|
# ? May 11, 2009 21:02 |
|
Unparagoned posted:Thanks. So do I just have a class and have an undo method in the class. Is it ok to have the do action in the init of the class? You really shouldn't. All this stuff can get wrapped up anyway so you only interact with it like my_game_state.do(new move_action(player1,left)); and my_game_state.undo(); Unparagoned posted:Sorry I got a bit confused. Here is what I though I'm talking about eliminating the part where you have to manually update your generic "undo anything" function. You shouldn't have to do that if you have a common action interface.
|
# ? May 11, 2009 21:07 |
|
Unparagoned posted:Thanks. So do I just have a class and have an undo method in the class. Is it ok to have the do action in the init of the class?
|
# ? May 11, 2009 21:13 |
|
Edit: Nevermind, misread.
|
# ? May 11, 2009 21:15 |
|
BigRedDot posted:Just to expand on this. Doing what you suggest limits your options, because it unnecessarily couples performing the action with object creation. What if you have complicated actions that are more easily configured by some builder, over several steps? If you *must* perform the action at object creation, this becomes impossible. If there is no reason to couple, don't couple. That makes sense. Thanks BigRedDot and Avenging Dentist. You've been very helpful.
|
# ? May 11, 2009 21:58 |
|
Unparagoned posted:Thanks. So do I just have a class and have an undo method in the class. Is it ok to have the do action in the init of the class? Having both do and undo be functions makes it much easier to support undo with redo. When you undo, simply move back in your container without popping the element off, then redo by just moving your iterator forward again and applying redo. If someone undoes several actions and then performs a different action, erase the corresponding elements from your current position in the queue to the end of the container and then push on a new element. If you have boost, I recommend you use Boost.CircularBuffer for your container, as it is perfect for your situation (fixed maximum size, pops elements off the opposing end as you push once you reach the max).
|
# ? May 11, 2009 22:09 |
|
By far the easiest way to implement undo is to maintain (1) a history of the last n actions the user took, together with (2) a copy of your internal state which looks exactly like what things were like n actions ago. Then, if the user asks to undo an operation, you can just restore from the copy and replay the last n-1 actions. The major problem with this approach is that you have to have a full copy of the state; sometimes you can use immutable structures to lower that cost, but sometimes it's just infeasible. I've found that explicitly-coded undo is usually a recipe for dozens of really subtle bugs, and eventually you'll probably want some operation whose undo implementation will basically require you to copy some fraction of the source data anyway. But your mileage may vary.
|
# ? May 11, 2009 22:52 |
|
|
# ? May 17, 2024 11:56 |
|
Am I right in thinking that if I have a class with a public static member, I should always initialise it in a .cpp file and not in the header? In case anyone wants the background, I had a class defined in the following header (no .cpp file): logisticcell.h code:
My solution was to create logisticcell.cpp, move the initialisation into there, then compile logisticcell.o and edit the project dependencies accordingly. As I said, I've already found a solution to this, but wanted to check that I've done the right thing.
|
# ? May 12, 2009 11:34 |