|
If all your plugins are going to be doing is parsing result data and determine what persistent-state updates are needed, then it really sounds like the best solution would be to just chuck a small scripting language in there and use that.
|
# ? Nov 9, 2010 05:44 |
|
|
# ? Jun 8, 2024 18:03 |
|
Jabor posted:If all your plugins are going to be doing is parsing result data and determine what persistent-state updates are needed, then it really sounds like the best solution would be to just chuck a small scripting language in there and use that. You're probably right that it would be the best solution, but as a one-man devteam I want to strike a balance between 'best' and 'quickest'.
|
# ? Nov 9, 2010 06:05 |
|
I guess I might just be underestimating how complex your persistence is, but surely it shouldn't be too complex to implement a comprehensive interface? I mean, what possible outcomes are there from a game? The user gained/lost {x} in-game currency? The user found {x}, {y} and {z} items? The user's rank changed by {x} points?
|
# ? Nov 9, 2010 06:19 |
|
Jabor posted:I guess I might just be underestimating how complex your persistence is, but surely it shouldn't be too complex to implement a comprehensive interface? And on the input side, I'm not sure how easy it would be for a Lua function to handle "here is a wad of data in the form of C structures serialized inside each other with the values in network byte order." (The interface can't handle converting this into something better because the structures are defined by the minigame, which doesn't yet exist.) Again, I'm not saying it's impossible, just it seems like it'd be a lot more work for very little extra benefit. Other things a game's scoring might want to do - refer to scores from other related games, access data about a guild/team of some sort, check how much you've played recently, assign achievements. roomforthetuna fucked around with this message at 07:19 on Nov 9, 2010 |
# ? Nov 9, 2010 07:15 |
|
roomforthetuna posted:And on the input side, I'm not sure how easy it would be for a Lua function to handle "here is a wad of data in the form of C structures serialized inside each other with the values in network byte order." (The interface can't handle converting this into something better because the structures are defined by the minigame, which doesn't yet exist.) There's at least three Lua libraries (struct, vstruct, and lpack) for packing and unpacking binary data, but at that point, why not just store the structures in Lua entirely and examine them from C as needed? This has the advantage of letting you easily determine their shape at runtime.
|
# ? Nov 9, 2010 08:04 |
|
roomforthetuna posted:Some of which may have characteristics that don't already exist, so now the interface needs to already have had a way of adding items that I didn't think of with characteristics that I didn't think of ... quote:Other things a game's scoring might want to do - refer to scores from other related games, access data about a guild/team of some sort, check how much you've played recently, assign achievements.
|
# ? Nov 9, 2010 09:57 |
|
ToxicFrog posted:There's at least three Lua libraries (struct, vstruct, and lpack) for packing and unpacking binary data, but at that point, why not just store the structures in Lua entirely and examine them from C as needed? This has the advantage of letting you easily determine their shape at runtime. quote:This isn't necessary unless you're going so far as to be generating new, unique items while the game is running. If you're just adding previously-unthought-of items when you add a new plugin or update one, this can be handled by manually updating the items database when you do that.
|
# ? Nov 9, 2010 17:01 |
|
roomforthetuna posted:I'm going to be adding a new plugin or updating one while the game is running!
|
# ? Nov 9, 2010 19:46 |
|
I am posting this as a last resort because it's insanity how much time I've spent on it and now it's become one of those problems I MUST SOLVE. Scenario: ISO-C, stdin parsing. Some thing simple like fgets or even getch in windows, right? No sweat! Yep, typed to it works fine. Moving on.. Oh wait it's not responding now that it's a child process with stdin redirected. That's odd, it's stopping at 700ish characters and just freezing. Maybe if I just setvbuf stdin to 4096 or redirect to a buffer or do 1 char at a time or... 3 days later I've tried every drat thing i can think of and that google can throw at me. The ONLY thing that will get it to work on linux OR windows (and i only have windows to test with) is by directly using GetStdHandle(STD_INPUT_HANDLE) (and then fread) which is proprietary windows. I also know it's not working in linux but can't really test there. Code can be any loop involving fgets,fgetc,getch,getchar,so on on stdin - fgets freezes completely but I can fetch one char at a time. fflush while not standard does not seem to do anything other than break it. I managed to attach to the running process and found that the buffer was getting data and I think windows is locking stdin like it would a file, which would explain the broken pipe - but I have no idea how to stop that in a portable solution (this is actually going to linux) I am tempted to just upgrade it to cpp and use cin but now it's a matter of learning what is wrong and I can't resist. So if anyone has any suggestions I would love to hear them - it can be c89 or c99 i'm just letting you know it's in c89. If anyone can help me out I've been googling +c -perl -python -"c++" +stdin <blah> forever and I've only found the one fread solution which is windows only, it would be a huge timesaver! Demerzel fucked around with this message at 02:56 on Nov 10, 2010 |
# ? Nov 10, 2010 02:52 |
|
Is there any way you can post something that compiles and exhibits the problem? If I understand correctly, a child process with stdin redirected hangs reading more than ~700 characters? But not with fread?
|
# ? Nov 10, 2010 05:59 |
|
Vanadium posted:Is there any way you can post something that compiles and exhibits the problem? Well what I was using was essentially a loop that read one char at a time (since fgets completely froze it) using the 'stdin' handle. It's really difficult to reproduce because piping a file to it works fine since it's a steady stream, as does typing to it - it's the generated on demand parent process that messes it up. here is my quick and dirty code to read one char/line at a time after fgets died on launch: http://pastebin.com/E39KjpDs What's sad is if i include <iostream> and convert the entire thing to cpp to add one line: code:
what DOES work (in windows) is the get handle STD_INPUT_HANDLE(DWORD -12) and freading it what happens with the above is it dies after about 700chars which i know because it's spitting back HI + whatever it's collected, i /think/ it's because windows locks the 'file' so the parent process can't write to it while reading it via getchar() note i've tried fgetc and __getch and every other iteration too Demerzel fucked around with this message at 07:48 on Nov 10, 2010 |
# ? Nov 10, 2010 07:41 |
|
Demerzel posted:Oh wait it's not responding now that it's a child process with stdin redirected. That's odd, it's stopping at 700ish characters and just freezing. Maybe if I just setvbuf stdin to 4096 or redirect to a buffer or do 1 char at a time or... To diagnose problems you should turn off buffering and do everything yourself. Or just use the low level call "_read" instead of fread. This is also portable. I am fairly sure that other APIs are no more powerful than _read. You can get weird behavior because the way you read data can affect the way the process on the other end of the pipe writes data. When you say fgets hangs, are you sure the writer process has written a newline?
|
# ? Nov 10, 2010 10:28 |
|
Yeah, your loop is wrong. If the process doesn't send a '\n' when it's done, you'll loop forever. You need to check for EOF when you call getchar() (and, assuming you're calling it in a loop, NULL when you call fgets()).
|
# ? Nov 10, 2010 13:11 |
|
Pooball posted:To diagnose problems you should turn off buffering and do everything yourself. Or just use the low level call "_read" instead of fread. This is also portable. Alright, that brings up a question then - how exactly do I turn off buffering? The ones I've seen look like this: setvbuf(stdin,(void*)NULL,_IOFNBF,0) also with just NULL or seen examples with _IOFBF but still 0 -- but my local compiler(VC, i know!) throws an exception on the 0 - though gcc might work. I also tried setting up buffering directly to the char* itself but that didn't work either. I also tried to redirect the BUFSIZ macro to 4096. However it's very possible I'm doing/thinking of it wrong. Re: fgets/newlines, yes I know exactly what it is sending - it's pure lines of approx 16-24 chars terminated by only one \n (as opposed to \r\n) The loop was a quick and dirty, I know it's not great - fgets was using a 128 char limit, if i was serious about it I'd at least be checking for 128. Also how would I check for EOF in stdin, would it even exist? I already tried using the standard int c, if c == EOF / FEOF and it never tripped, was in fact one of the first things I tried. I"ll take a look at __read -- I am curious how the hell std::cin.getline() works perfectly whether compiled with gcc or vc to be honest.
|
# ? Nov 10, 2010 15:36 |
|
For getchar():code:
Demerzel posted:However it's very possible I'm doing/thinking of it wrong.
|
# ? Nov 10, 2010 16:04 |
|
Mustach posted:Yeah, you're kind of flipping out a little bit and assuming that the C runtime is broken, when it's much more likely that your code just has a typo or something like that. What does your fgets() version look like? What characters are sent by the parent process at the 700 mark? What does the parent process's code look like? You're missing the point of the code I posted - that is one of a dozen methods I've tried, I'm well aware it's not safe or optimal, it's just a hack to try to make it past whatever breaking point and have it spit out what it's got so far since I know exactly what input is going to it. The parent process code is not written by me - it's python and I can get the source but any other language (including C++) has no issue handling the redirected stdin. The rest of the code is irrelevant to this issue since I took it completely out while working on this problem and still have it, essentially what it does is parse the lines, looking for a go\n to indicate that input is done, then parses it and sends a go\n back. The character at the 807 mark that broke it last time was just a generic ascii digit. It does break at the same point regardless of what method I use to pull 1 char at a time, if I use fgets it never gets to the point of being able to fprintf(stderr,io_output). If I substitute other data it breaks somewhere between 7-900 chars, always at the same point for that particular dataset but not particular to a char or number of chars. I'm not assuming the C runtime is broken, I'm assuming that there's something I'm missing here, it's uncommon enough that I am finding tons of one-off stuff but nothing directly related, except a few links to an msdn article that had the working windows code. The fact that I literally can replace io_receiveLine() with std::cin.getline(io_output) and have it work perfectly tells me there is /something/ i need to do that cin does that fgets etc does not. What that is I have no idea. Demerzel fucked around with this message at 16:29 on Nov 10, 2010 |
# ? Nov 10, 2010 16:23 |
|
Demerzel posted:You're missing the point of the code I posted - that is one of a dozen methods I've tried, I'm well aware it's not safe or optimal, …
|
# ? Nov 10, 2010 17:29 |
|
Mustach posted:Then how about you show us the actual implementation with fgets() that want to use, instead of some hack that you typed out in desperation? Everyone's just going to guess until you post the code. code:
Demerzel fucked around with this message at 18:06 on Nov 10, 2010 |
# ? Nov 10, 2010 17:32 |
|
Demerzel posted:
|
# ? Nov 10, 2010 18:26 |
|
roomforthetuna posted:Are you sure it's actually freezing on the fgets, not being stuck in the inputDone loop while fgets repeatedly returns NULL? No I'm not at all sure where exactly it's freezing. I'm basing the idea that it's freezing on fgets is because when I stick a fprintf(stderr,"output: %s",io_stdin); after it nothing ever appears vs with fgetc or getchar I do get input back. I assumed that if it returned null (ie not a pointer to io_stdin) it would loop back, if that's wrong that definitely be an issue. Actually one thing I'm considering is the fgets is specifically looking for '\r\n' since I'm on windows, which doesn't exist. However, the same code deployed to linux has the same issue. scanf however does fix the issue, but I'm not sure how not to have to hack in the \n since it goes to spaces, how would you set up a scanf expression to mimic the behavior of fgets? vvv correct vvv Demerzel fucked around with this message at 20:15 on Nov 10, 2010 |
# ? Nov 10, 2010 20:11 |
|
Demerzel posted:No I'm not at all sure where exactly it's freezing. I'm basing the idea that it's freezing on fgets is because when I stick a fprintf(stderr,"output: %s",io_stdin); after it nothing ever appears vs with fgetc or getchar I do get input back.
|
# ? Nov 10, 2010 20:15 |
|
So, I've recently decided to roll up my sleeves and start reading some beginner C++ manuals. I've come across something that I'm having a bit of trouble wrapping my head around (and sorry if this is kind of stupid question, I'm very much interested in the whys of things) but it says something like: "assuming two boolean values p and q, a logical XOR is constructed as such:" code:
p is ORed with q which means if either one is true, then the operation is true (in a truth table three out of four possibilities are then true). Then p and q are ANDed with a NOT operator in front of the operation, so the time when the operation would equate to true is when p and q are not both true (which would be three out of four possibilities again). This is ANDed with the initial OR operation to make an XOR (in which one and only one operand is true)? I'm not getting it. If anyone could maybe explain the logic behind it to me better it would be appreciated... I feel kind of dumb asking something like this! A Bloody Crowbar fucked around with this message at 20:49 on Nov 10, 2010 |
# ? Nov 10, 2010 20:46 |
|
"one and only one operand is true" is the same as "at least one is true, but not both". "at least one is true" is p || q, and "not both" is !(p && q).
|
# ? Nov 10, 2010 20:50 |
|
Vanadium posted:"one and only one operand is true" is the same as "at least one is true, but not both". "at least one is true" is p || q, and "not both" is !(p && q). Yeah that makes sense. For some reason I wasn't thinking that this would eliminate both operands being true equating a typical or operation to true so it was confusing me as to why you would do this. stupid
|
# ? Nov 10, 2010 20:58 |
|
XOR is just bitwise !=
|
# ? Nov 10, 2010 21:17 |
|
I'm getting this error: "Game.h:39: error: expected `;' f?re symbolen '('" and this is my game class: code:
|
# ? Nov 10, 2010 21:51 |
|
Mopp posted:I'm getting this error: "Game.h:39: error: expected `;' f?re symbolen '('" You fail to include a header file declaring SDL_Surface/you are not forward declaring SDL_Surface/you include a broken header file?
|
# ? Nov 10, 2010 21:57 |
|
Zerf posted:You fail to include a header file declaring SDL_Surface/you are not forward declaring SDL_Surface/you include a broken header file? well, no. I copied the entire file here: http://pastebin.com/w5ELYspc it complains at the SDL_Surface* load_image(std::string); and the only error message i'm getting is Game.h:50: error: expected `;' f?re symbolen '('
|
# ? Nov 10, 2010 22:04 |
|
Mopp posted:well, no. I copied the entire file here: http://pastebin.com/w5ELYspc
|
# ? Nov 10, 2010 22:10 |
|
Well, I solved it. Just for anyone who randomly comes across the same problem the only way I could get it to work was to only use functions that do not specify stdin/stdout. So I ended up with a getchar loop and a putchar loop followed by fflush.
|
# ? Nov 10, 2010 22:11 |
|
I am working on another basic homework assignment thing and I'm having a weird problem, and I can't figure out what is causing it. A small note is that the class (which is really a free online class thing, they filmed a computer science course at a college and put it up) uses its own library that contains the command GetFloat, which I don't think is a normal C command. It gets a float, which is pretty obvious. Anyway, the code up to the point of issue: code:
code:
code:
|
# ? Nov 11, 2010 06:19 |
|
nevermind
pseudorandom name fucked around with this message at 06:31 on Nov 11, 2010 |
# ? Nov 11, 2010 06:26 |
|
wlokos posted:I'm assuming that this is some kind of rounding issue, perhaps I'm misunderstanding something about how floats/ints work? Any help on how I could fix that issue would be really appreciated. Yep. 51/100ths can't be expressed in closed form as a binary number, so the float is inevitably going to be slightly smaller or larger than the true value, and multiplying it by 100 won't necessarily give you exactly the original numerator. The "right" solution is to not read it in as a float in the first place; if that's not possible/worthwhile, just add a small number before rounding to make sure that you get something slightly larger than the nearest integer.
|
# ? Nov 11, 2010 08:23 |
|
If I didn't want to read it as a float, what would I read it as? I thought that ints couldn't hold tenths/hundrenths of a number, so that wouldn't work either if the user was going to enter in anything other than an integer... or is that not right?
|
# ? Nov 11, 2010 17:16 |
|
wlokos posted:If I didn't want to read it as a float, what would I read it as? I thought that ints couldn't hold tenths/hundrenths of a number, so that wouldn't work either if the user was going to enter in anything other than an integer... or is that not right? $0.51 (float) is also 51 cents (integer), for one example. You just need to change your internal units, converting the user input by hand, if that is an option.
|
# ? Nov 11, 2010 17:31 |
|
People tend to yell at you for using floating point numbers/operations (which are necessarily imprecise) for currencies anyway, and you just found out why!
|
# ? Nov 11, 2010 17:47 |
|
Vanadium posted:People tend to yell at you for using floating point numbers/operations (which are necessarily imprecise) for currencies anyway, and you just found out why! Yeah, he got off pretty easy, didn't he?
|
# ? Nov 11, 2010 17:52 |
|
Ugg boots posted:Yeah, he got off pretty easy, didn't he? if you're just learning its one thing, if you're programming bank software it's kind of another thing. For that matter, bad beginner CS classes seem to love to use floats for currency because bad professors think their students are idiots and won't be able to comprehend any other use for decimal numbers. whatever instructor made that assignment should be run up a flagpole, not their students. edit: Lol it's Harvard. What a bunch of tools. https://www.cs50.net/psets/1/pset1.pdf evensevenone fucked around with this message at 20:45 on Nov 11, 2010 |
# ? Nov 11, 2010 20:41 |
|
BigRedDot posted:$0.51 (float) is also 51 cents (integer), for one example. You just need to change your internal units, converting the user input by hand, if that is an option. How would I go about "converting the user input by hand"? I don't know of any way to make a float into an int (or otherwise handle the input properly) other than the way that I did it. I am extremely new to programming so I apologize for being slow! and thanks to everybody for the help, I really appreciate it.
|
# ? Nov 11, 2010 21:14 |
|
|
# ? Jun 8, 2024 18:03 |
|
wlokos posted:How would I go about "converting the user input by hand"? I don't know of any way to make a float into an int (or otherwise handle the input properly) other than the way that I did it. I am extremely new to programming so I apologize for being slow!
|
# ? Nov 11, 2010 21:19 |