The Big Programming Thread - Page 427
| Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
|
Shikada
Serbia976 Posts
| ||
|
sluggaslamoo
Australia4494 Posts
On January 15 2014 08:43 Zocat wrote: It's called busy spin / spin lock afaik. Overall you should avoid using it, since it just burns the CPU. I think one thing were you can use it was when you only have to wait for very very short amount of times where implementing events would introduce a larger overhead. (No idea if that's true though, never used it) Its called a latch function, its used a lot more than you think. ![]() | ||
|
Shield
Bulgaria4824 Posts
On January 15 2014 09:29 sluggaslamoo wrote: Its called a latch function, its used a lot more than you think. ![]() Wikipedia seems to suggest "busy-waiting or spinning". | ||
|
sluggaslamoo
Australia4494 Posts
Oops brain fart, you pass in the latch function to the spinlock/poller/whateveryouwannacallit. ![]() The proper way to do it would be to create a function that takes a latch function that returns a promise. An example of this is the "waitsFor" function in Jasmine. Its really just an asynchronous while loop that takes functions as parameters. http://pivotal.github.io/jasmine/#section-24 | ||
|
Pucca
Taiwan1280 Posts
StarCraft 1 like any program has independent data strings for each piece of information in the game. My goal is to read this data string and place it into a constantly updating .txt file. There are two data strings I have, Total Score of Player A and Total Score of Player B. I want to combine the two. So like Player A is 15 Player B is 14 the output becomes 29 places into the text file. So my logic is Data stream of Player A is A Data stream of Player B is B ReadProcessData of A ReadProcessData of B combine? (I don't know C++ function to add) A and B to result in C Fstream C to TeamA.txt **refresh every .2sec** As long as the data streams are consider variables you can add them no? Any assistance is appreciate, if you'd like to help me please PM me. Thanks. | ||
|
Shield
Bulgaria4824 Posts
Let me know if I am mistaken, but I wasn't able to do this once. | ||
|
Tobberoth
Sweden6375 Posts
On January 15 2014 22:35 Pucca wrote: I'm working on a C++ program, I'm a noob so I was wondering if anyone could give some tips on my logic. StarCraft 1 like any program has independent data strings for each piece of information in the game. My goal is to read this data string and place it into a constantly updating .txt file. There are two data strings I have, Total Score of Player A and Total Score of Player B. I want to combine the two. So like Player A is 15 Player B is 14 the output becomes 29 places into the text file. So my logic is Data stream of Player A is A Data stream of Player B is B ReadProcessData of A ReadProcessData of B combine? (I don't know C++ function to add) A and B to result in C Fstream C to TeamA.txt **refresh every .2sec** As long as the data streams are consider variables you can add them no? Any assistance is appreciate, if you'd like to help me please PM me. Thanks. Isn't this a very roundabout way of doing it? Isn't it better to parse the data from the processes into strings, then simply write these strings to the common file when they change? | ||
|
synd
Bulgaria586 Posts
On January 15 2014 22:52 darkness wrote: I can't help with C++ but variables cannot be added if there is no + operator implementation. Example in Java (generics, called template in C++):
Let me know if I am mistaken, but I wasn't able to do this once.
.... profit? | ||
|
nunez
Norway4003 Posts
On January 15 2014 22:35 Pucca wrote: I'm working on a C++ program, I'm a noob so I was wondering if anyone could give some tips on my logic. StarCraft 1 like any program has independent data strings for each piece of information in the game. My goal is to read this data string and place it into a constantly updating .txt file. There are two data strings I have, Total Score of Player A and Total Score of Player B. I want to combine the two. So like Player A is 15 Player B is 14 the output becomes 29 places into the text file. So my logic is Data stream of Player A is A Data stream of Player B is B ReadProcessData of A ReadProcessData of B combine? (I don't know C++ function to add) A and B to result in C Fstream C to TeamA.txt **refresh every .2sec** As long as the data streams are consider variables you can add them no? Any assistance is appreciate, if you'd like to help me please PM me. Thanks. not quite sure what you mean with data-string, but assuming you have some arithmetic value stored in a text-string (something like "420" or "4.20") you can convert from a basic_string to arithmetic through functions like stoi and stof etc... string to int -> stoi string to float -> stof if you just add two strings with the binary + operator you will append the rhs string to the lhs string. string text="42.0"; their 'counterpart' is the to_string function that converts arithmetic into string, a la the integer 420 to the string "420". here's a contrived example... string t_0="32"; | ||
|
Pucca
Taiwan1280 Posts
On January 15 2014 23:06 Tobberoth wrote: Isn't this a very roundabout way of doing it? Isn't it better to parse the data from the processes into strings, then simply write these strings to the common file when they change? Well, sure, If the refresh rate can be dependent upon when the value is change for sure, but each output file needs to be independent from each other in order to put into practical use. | ||
|
Arnstein
Norway3381 Posts
+ Show Spoiler +
Edit: Nevermind, forgot & before the ints, the most common mistake in the world... | ||
|
Dknight
United States5223 Posts
| ||
|
WarSame
Canada1950 Posts
On January 14 2014 11:39 sluggaslamoo wrote: Yep basically what you said and not much more than that if at all. Those classes will basically serve as "models". Controllers handle inputs. For example in a website it will handle the URL's, in your case its the game controller inputs. There should be minimal logic in the controller. Think about how much logic is in an actual game controller, it takes a signal, and converts it into an instruction to the game, that's all your controller should do as well. As a rule of thumb, light controllers, fat models. Pretty much all the logic should be in your models. Anything code that has anything to do with a model, should be in the model itself. For example, "moving a Paddle", there should be a move method on the Paddle itself, don't write the logic in the controller or anywhere else. In the controller you would handle the mouse movement, and delegate all logic to the Paddle by passing in the mouse event or minimal information necessary. You could also do it declaratively, by adding in a listener to the paddle in the beginning and firing it off with the controller. When I was saying that your last example was MVC, I was more or less being tongue in cheek about MVC not being the issue there. When you do things properly your program will naturally become MVC of sorts. Even when you do implement what I said, it won't be MVC really. MVC normally has an ORM associated with it, and you declare Models as an abstraction for saveable/stateful components in your application. I only pointed it out because you specifically wanted your app to be MVC. I don't think its necessary to think of it like that though. MVC is much more useful for applications where you need to save state. This is more or less focused on doing Responsibility Driven Design. Thank you to you and Blisse. I redid the design a bit and made it more MVC-like. I moved the data logic into PongData and created my Paddle and Ball classes. It turned out fairly nicely, I think, but there's still a few parts where it doesn't look as great as it probably could. Also, for some reason every once in a while the ball simple doesn't collide with the paddle and clips right through, but I can't track down why. For now, it's likely done. At some point in the future I may come back and add in Ball[] and Paddle[] in order to allow for extras to be added in on demand. The code is here: https://github.com/WarSame/PongGraeme | ||
|
sluggaslamoo
Australia4494 Posts
On January 17 2014 10:33 WarSame wrote: Thank you to you and Blisse. I redid the design a bit and made it more MVC-like. I moved the data logic into PongData and created my Paddle and Ball classes. It turned out fairly nicely, I think, but there's still a few parts where it doesn't look as great as it probably could. Also, for some reason every once in a while the ball simple doesn't collide with the paddle and clips right through, but I can't track down why. For now, it's likely done. At some point in the future I may come back and add in Ball[] and Paddle[] in order to allow for extras to be added in on demand. The code is here: https://github.com/WarSame/PongGraeme Its possible that the ball may moving too many units per frame, so there is never a frame where they actually collide, the ball just jumps right past it. I haven't seen the code though. If you think this is the case, have a look at interpolation. Basically at each frame you look at where the ball has been since the last frame and see if they should have collided. | ||
|
WarSame
Canada1950 Posts
if the ball is not in the paddle, and the ball will be in the paddle on the next cycle, make the ball bounce. Depending on where it hit the paddle it then bounces differently. Also, it seems kinda odd that you can use a Double to store the ball location and then paint it onto the screen as an int. I suppose the graphics library for Java has some sort of rounding function. Is that wrong? | ||
|
sluggaslamoo
Australia4494 Posts
On January 17 2014 11:16 WarSame wrote: Well the way I handled the collision was: if the ball is not in the paddle, and the ball will be in the paddle on the next cycle, make the ball bounce. Depending on where it hit the paddle it then bounces differently. Also, it seems kinda odd that you can use a Double to store the ball location and then paint it onto the screen as an int. I suppose the graphics library for Java has some sort of rounding function. Is that wrong? How do you check that the ball will be in the paddle on the next cycle though. Ill give you an example
The top row is distance units O is the ball [] is the paddle If the ball moves 4 units per frame it will never hit the paddle, causing the collision to never happen. With interpolation it would be like this Woops the ball missed
Do a line collision test between the two points and the ball can bounce. @Other question: No clue, it probably get typecasted to an int. | ||
|
WarSame
Canada1950 Posts
EDIT: So it's close to what you said. In my case it interpolated between the 2 points of the paddle location and the paddle thickness plus location. | ||
|
sluggaslamoo
Australia4494 Posts
On January 17 2014 11:27 WarSame wrote: For checking if it will be in the paddle on the next cycle I used the current position and the speed. I first check whether the current position was outside the paddle. Then I checked if the next position was inside the paddle. If it was I bounced the ball off of the paddle. This is the same as only checking once, but moving the ball after the check. On January 17 2014 11:27 WarSame wrote: For checking if it will be in the paddle on the next cycle I used the current position and the speed. I first check whether the current position was outside the paddle. Then I checked if the next position was inside the paddle. If it was I bounced the ball off of the paddle. EDIT: So it's close to what you said. In my case it interpolated between the 2 points of the paddle location and the paddle thickness plus location. Are you sure its interpolation and not just checking two points? | ||
|
Chocolate
United States2350 Posts
For each language that I know, 9 small projects, 5 medium projects, and one big one. I currently know Java and Python, and I'm looking at learning C++, C#, C, PHP, and Ruby (on rails). In addition, I would add every solution that I have made from project euler, hopefully at least 100 of them. Small projects would be just simple computations, perhaps rudimentary physics solvers, and other basic implementations of science stuff. Maybe some basic encryption. Medium projects would be more developed simulators, maybe some games, and generally projects with neater interfaces than just the command terminal. Also, simple web stuff. Decryption as well. Big projects would be things like apps, websites, maybe an actual physics environment, things like that. First is this a decent selection of languages if I want to keep my options open for web or more general software? Is it feasible to finish this all in four years working sparingly at a pace of around 5 hr per week? Also, is it generally acceptable to include things you made for a class in a portfolio? Thanks in advance. I have a feeling that all these stupid code/STEM PR and awareness programs are going to push a lot of scrubs into CS so I want to be one of the better candidates for internships and jobs. | ||
|
WarSame
Canada1950 Posts
On January 17 2014 11:54 sluggaslamoo wrote: This is the same as only checking once, but moving the ball after the check. Are you sure its interpolation and not just checking two points? You're right. It's just checking points. I'm confused as to how you would do interpolation though? I've never seen that in any of my classes(which I'm increasingly believing are a waste of time and money). | ||
| ||

