Hey, what is it called when big problem is broken down into multiple smaller problems/steps?
For example (from my previous experience few years ago): I need to make a website with user registration etc..
I don't know anything about programming or databases, I don't know where to start, so I break down:
Big Problem: Make a website with registration.
Broken down into smaller problems:
First of all: Learn website structure/hosting etc..
1) Draw picture of rough website design/idea.
2) Learn HTML and create all buttons, pics, forms.
3) Learn CSS and design all HTML items (buttons, forms, divs etc..)
4) Learn PHP for handling user input.
5) Learn MySQL for data storage.
6) Learn JavaScript to make website a bit nicer looking.
7) Upload website and run it.
Done, problem solved now.
So huge problem broken down into steps/smaller problems.
Is there specific name for such process in world of programming/development/IT?
[QUOTE=KinderBueno;46800548]Hey, what is it called when big problem is broken down into multiple smaller problems/steps?
...
Done, problem solved now.
So huge problem broken down into steps/smaller problems.
Is there specific name for such process in world of programming/development/IT?[/QUOTE]
Decomposition, perhaps?
[QUOTE=KinderBueno;46800548]Hey, what is it called when big problem is broken down into multiple smaller problems/steps?
For example (from my previous experience few years ago): I need to make a website with user registration etc..
I don't know anything about programming or databases, I don't know where to start, so I break down:
Big Problem: Make a website with registration.
Broken down into smaller problems:
First of all: Learn website structure/hosting etc..
1) Draw picture of rough website design/idea.
2) Learn HTML and create all buttons, pics, forms.
3) Learn CSS and design all HTML items (buttons, forms, divs etc..)
4) Learn PHP for handling user input.
5) Learn MySQL for data storage.
6) Learn JavaScript to make website a bit nicer looking.
7) Upload website and run it.
Done, problem solved now.
So huge problem broken down into steps/smaller problems.
Is there specific name for such process in world of programming/development/IT?[/QUOTE]
Other than just "non-naive design"?
As Tommy stated, [url=http://en.wikipedia.org/wiki/Decomposition_%28computer_science%29]it is indeed decomposition[/url].
And it is a very fundamental approach to systems design, and is generally one of the first things taught in formal computer systems design courses.
I'm working with SFML in Visual Studio and I'm having a bit of an issue getting my window to display anything proper. I followed the original tutorial for setting it up with SFML and it would display a circle just fine. When I went to get a better game loop flow, something happened and now the window isn't even clearing and I cannot figure out why (Window stays white). Here is my code:
[code]#include <SFML/Graphics.hpp>
#include <Windows.h>
int updateGame(sf::Time elapsed);
int displayGame(float interpolation);
sf::RectangleShape shape;
sf::RenderWindow window;
int main(){
sf::RenderWindow window(sf::VideoMode(800, 600), "Galaga");
window.clear(sf::Color::Black);
sf::RectangleShape shape(sf::Vector2f(120, 50));
shape.setFillColor(sf::Color::Green);
sf::Clock clock;
clock.restart();
//Keep track of time & frames
const int TICKS_PER_SECOND = 25;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;
DWORD next_game_tick = GetTickCount();
int loops;
float interpolation;
bool game_is_running = true;
while (window.isOpen()) {
loops = 0;
while (GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {
updateGame(clock.getElapsedTime());
next_game_tick += SKIP_TICKS;
loops++;
}
interpolation = float(GetTickCount() + SKIP_TICKS - next_game_tick) / float(SKIP_TICKS);
displayGame(interpolation);
}
return 0;
}
int updateGame(sf::Time elapsed){
sf::Event event;
while (window.pollEvent(event)){
//Update based on the events
}
if (elapsed.asSeconds() >= 10){
printf("Elapsed: %f\n", elapsed.asSeconds());
shape.setFillColor(sf::Color::Blue);
}
return 0;
}
int displayGame(float interpolation){
window.clear();
window.draw(shape);
window.display();
return 0;
}[/code]
Here was the original tutorial I followed that got a green circle rendering:
[url]http://www.sfml-dev.org/tutorials/2.2/start-vc.php[/url]
[QUOTE=mastersrp;46799888]In what language is that even a thing?
[editline]26th December 2014[/editline]
sneaky basterd[/QUOTE]
C
[QUOTE=RedBlade2021;46807934]I'm working with SFML in Visual Studio and I'm having a bit of an issue getting my window to display anything proper. I followed the original tutorial for setting it up with SFML and it would display a circle just fine. When I went to get a better game loop flow, something happened and now the window isn't even clearing and I cannot figure out why (Window stays white). Here is my code:
[code]#include <SFML/Graphics.hpp>
#include <Windows.h>
int updateGame(sf::Time elapsed);
int displayGame(float interpolation);
sf::RectangleShape shape;
sf::RenderWindow window;
int main(){
sf::RenderWindow window(sf::VideoMode(800, 600), "Galaga");
window.clear(sf::Color::Black);
sf::RectangleShape shape(sf::Vector2f(120, 50));
shape.setFillColor(sf::Color::Green);
sf::Clock clock;
clock.restart();
//Keep track of time & frames
const int TICKS_PER_SECOND = 25;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;
DWORD next_game_tick = GetTickCount();
int loops;
float interpolation;
bool game_is_running = true;
while (window.isOpen()) {
loops = 0;
while (GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {
updateGame(clock.getElapsedTime());
next_game_tick += SKIP_TICKS;
loops++;
}
interpolation = float(GetTickCount() + SKIP_TICKS - next_game_tick) / float(SKIP_TICKS);
displayGame(interpolation);
}
return 0;
}
int updateGame(sf::Time elapsed){
sf::Event event;
while (window.pollEvent(event)){
//Update based on the events
}
if (elapsed.asSeconds() >= 10){
printf("Elapsed: %f\n", elapsed.asSeconds());
shape.setFillColor(sf::Color::Blue);
}
return 0;
}
int displayGame(float interpolation){
window.clear();
window.draw(shape);
window.display();
return 0;
}[/code]
Here was the original tutorial I followed that got a green circle rendering:
[url]http://www.sfml-dev.org/tutorials/2.2/start-vc.php[/url][/QUOTE]
The problem is because your global sf::RenderWindow object is not being initialized, and inside of main you are making a new scoped variabled (Also called window).
Your code is pretty terrible (Sorry, being honest) and you should avoid using global variables (Especially dont use global sf::RenderWindow) whenever possible. Instead, you should look at passing the window down to the functions.
Also why do updateGame and displayGame have integer return types and only return 0? Why not make them void instead?
[b]Edit:[/b]
I modified your code into something that should work (Untested)
[code]
#include <SFML/Graphics.hpp>
#include <Windows.h>
namespace
{
sf::RectangleShape shape;
} // namespace (anonymous)
void updateGame(sf::RenderWindow& roRenderWindow, const float kfDelta)
{
sf::Event event;
while (roRenderWindow.pollEvent(event)){
//Update based on the events
switch(event.type) {
case(sf::Event::Closed) : {
roRenderWindow.close();
break;
}
}
}
if (kfDelta >= 10.0f){
printf("Elapsed: %f\n", kfDelta);
shape.setFillColor(sf::Color::Blue);
}
}
void displayGame(sf::RenderWindow& roWindow, float interpolation)
{
roWindow.clear();
roWindow.draw(shape);
roWindow.display();
}
int main(){
sf::RenderWindow window(sf::VideoMode(800, 600), "Galaga");
shape = sf::RectangleShape{sf::Vector2f(120, 50)};
shape.setFillColor(sf::Color::Green);
//Keep track of time & frames
const int TICKS_PER_SECOND = 25;
const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
const int MAX_FRAMESKIP = 5;
DWORD next_game_tick = GetTickCount();
int loops;
float interpolation;
sf::Clock clock;
while (window.isOpen()) {
loops = 0;
while (GetTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {
updateGame(window, clock.getElapsedTime().asSeconds());
next_game_tick += SKIP_TICKS;
loops++;
}
interpolation = float(GetTickCount() + SKIP_TICKS - next_game_tick) / float(SKIP_TICKS);
displayGame(window, interpolation);
clock.reset();
}
return 0;
}
[/code]
[QUOTE=mastersrp;46799888]In what language is that even a thing?
[editline]26th December 2014[/editline]
sneaky basterd[/QUOTE]
Any decent language?
I think people often forget (and I am admittedly one of them), that the true form of the for loop is
[code]for (initialization; true-proceed-condition; at-loop-end-statement)[/code]
And you can do all kinds of fun things with it. A fun one I like to do is.
[code]
bool doLoop = true;
for (int counter=0; doLoop; counter++) {
...
someFunc(counter);
...
if (someCodition) doLoop = false;
}
[/code]
All that trick is, is merging that fact with the prefixed ++ operator, which most all decent languages support. I [b]think[/b] you can even have multi-operation statements in that last clause, but I'm not sure, and don't have time to test. I would imagine it probably uses curly braces though, being analogous to if statements (it's normal form being analogous to single-operation if statements).
[QUOTE=G4MB!T;46808008]The problem is because your global sf::RenderWindow object is not being initialized, and inside of main you are making a new scoped variabled (Also called window).
Your code is pretty terrible (Sorry, being honest) and you should avoid using global variables (Especially dont use global sf::RenderWindow) whenever possible. Instead, you should look at passing the window down to the functions.
Also why do updateGame and displayGame have integer return types and only return 0? Why not make them void instead?[/QUOTE]Ahh okay thanks. To be honest, I'm newer with C++ and am using this as a way to jump into it. I'm also just trying to piece together how each part of SFML works one step at a time (Starting with the window...) Thanks for the advice and help!
It is advised by a lot of people (Including by the SFML team) that you start with a C++ tutorial instead of SFML as it gets quite complicated if you dont know the basics.
[QUOTE=G4MB!T;46808162]It is advised by a lot of people (Including by the SFML team) that you start with a C++ tutorial instead of SFML as it gets quite complicated if you dont know the basics.[/QUOTE]I thought I knew most of the basics since I took a class on it, but it would seem there's still a lot that I don't know.
Happens to everyone. I'll admit that most tutorials for C++ these days are obselete and dont cover the basics of C++11/14. I'll also agree that tutorials dont teach everything and you dont really know what you are missing until you need it. [URL="http://www.stroustrup.com/Tour.html"]Bjarne Stroustrup[/URL] and [URL="http://shop.oreilly.com/product/0636920033707.do"]Scott Meyers[/URL] have both released books detailing C++11 semtantics and [URL="http://herbsutter.com/"]Herb Sutter[/URL] has some good blog articles which are worth reading.
[QUOTE=Gmod4ever;46808076]Any decent language?
I think people often forget (and I am admittedly one of them), that the true form of the for loop is
[code]for (initialization; true-proceed-condition; at-loop-end-statement)[/code]
And you can do all kinds of fun things with it. A fun one I like to do is.
[code]
bool doLoop = true;
for (int counter=0; doLoop; counter++) {
...
someFunc(counter);
...
if (someCodition) doLoop = false;
}
[/code]
All that trick is, is merging that fact with the prefixed ++ operator, which most all decent languages support. I [b]think[/b] you can even have multi-operation statements in that last clause, but I'm not sure, and don't have time to test. I would imagine it probably uses curly braces though, being analogous to if statements (it's normal form being analogous to single-operation if statements).[/QUOTE]
You can have multiple things in all 3 blocks, as long as you seperate them using comma's
[cpp]
for (printf("a"), printf("b"); true != true, false == false; printf("c"))
{
}
[/cpp]
For the "true-proceed-condition", it just requires the last statement to be true, it ignores the result of the rest.
[QUOTE=Cold;46808259]You can have multiple things in all 3 blocks, as long as you seperate them using comma's
[cpp]
for (printf("a"), printf("b"); true != true, false == false; printf("c"))
{
}
[/cpp]
For the "true-proceed-condition", it just requires the last statement to be true, it ignores the result of the rest.[/QUOTE]
Also please don't do this. Ever.
It's not idiomatic and the only thing you'll do is confuse others reading your code and then yourself later.
using SFML, how do you make a sprite completely white?
if you set the colour to 255,255,255,255, it just means that no colours are subtracted from the texture, but I want every pixel (except for the alpha pixels) to turn white.
is this possible easily? I tried using renderstates, setting the BlendMode to 'BlendAdd' makes my texture golden instead of white for some reason.
anyone else got any luck on this?
[QUOTE=war_man333;46810291]using SFML, how do you make a sprite completely white?
if you set the colour to 255,255,255,255, it just means that no colours are subtracted from the texture, but I want every pixel (except for the alpha pixels) to turn white.
is this possible easily? I tried using renderstates, setting the BlendMode to 'BlendAdd' makes my texture golden instead of white for some reason.
anyone else got any luck on this?[/QUOTE]
The two methods that come to mind for me would be 1.) literally swap the sprite out for a white version of it or 2.) use a shader that sets each pixel on the sprite to white but preserves the alpha value of the original.
I'm sure there are other ways, but those are the two I think of straight away.
[QUOTE=BackwardSpy;46810418]The two methods that come to mind for me would be 1.) literally swap the sprite out for a white version of it or 2.) use a shader that sets each pixel on the sprite to white but preserves the alpha value of the original.
I'm sure there are other ways, but those are the two I think of straight away.[/QUOTE]
I thought of method 1 too, but that gets really annoying if you have lots of different bombs or whatever that need to blink. I'll try looking more into shaders. It's a tad confusing when you just want something to be white, not some glowy shit.
Where is the money at in CS? What specific fields pay more than others?
[code]
Wall w1(tileManage(0).x, tileManage(0).y, "wall_brick");
Wall w2(tileManage(20).x, tileManage(20).y, "wall_brick");
Wall w3(tileManage(40).x, tileManage(40).y, "wall_brick");
Wall w4(tileManage(60).x, tileManage(60).y, "wall_brick");
Wall w5(tileManage(80).x, tileManage(80).y, "wall_brick");
Wall w6(tileManage(100).x, tileManage(100).y, "wall_brick");
Wall w7(tileManage(120).x, tileManage(120).y, "wall_brick");
Wall w8(tileManage(140).x, tileManage(140).y, "wall_brick");
Wall w9(tileManage(160).x, tileManage(160).y, "wall_brick");
entities.push_back(&player);
entities.push_back(&enemy);
entities.push_back(&w1);
entities.push_back(&w2);
entities.push_back(&w3);
entities.push_back(&w4);
entities.push_back(&w5);
entities.push_back(&w6);
entities.push_back(&w7);
entities.push_back(&w8);
entities.push_back(&w9);[/code]
What's the efficient way of doing this?
tried doing this:
[code]
for (int i = 0; i < 9; i++)
{
sf::Vector2i tile = tileManage(i*20);
entities.push_back(&(Wall(tile.x, tile.y, "wall_brick")));
}[/code]
but I get a 'pure virtual function call'. What do I do?
Dunno if more code is necesarry to kill the problem, please do tell.
You cant reference temporary objects.
[QUOTE=proboardslol;46812199]Where is the money at in CS? What specific fields pay more than others?[/QUOTE]
Why would that ever matter?
[QUOTE=mastersrp;46812579]Why would that ever matter?[/QUOTE]
To make money? I want to make a better life for myself and my family and I need money to do that.
[editline]28th December 2014[/editline]
Do Fourier transformations return the frequency of a sample? If I have. 1 sec 2400hz sample, will it return 2400?
[QUOTE=proboardslol;46812618]To make money? I want to make a better life for myself and my family and I need money to do that.
[editline]28th December 2014[/editline]
Do Fourier transformations return the frequency of a sample? If I have. 1 sec 2400hz sample, will it return 2400?[/QUOTE]
I don't know of any CS work you can do that doesn't pay at least more than average income, although there probably is some.
[QUOTE=G4MB!T;46812570]You cant reference temporary objects.[/QUOTE]
how do I not make them temporary? do I have to declare them manually?
You should consider the scope of your variables. Taking a the reference of a variable inside a function and adding it to a vector that has class scope will result in undefined behaviour (Like a crash) when you try and access it in the vector. Direct heap allocation is ill-advised so I would suggest looking at C++11 smart pointers (Unique/shared pointer) and using std::make_unique.
[QUOTE=G4MB!T;46812924]You should consider the scope of your variables. Taking a the reference of a variable inside a function and adding it to a vector that has class scope will result in undefined behaviour (Like a crash) when you try and access it in the vector. Direct heap allocation is ill-advised so I would suggest looking at C++11 smart pointers (Unique/shared pointer) and using std::make_unique.[/QUOTE]
I don't have anything called std::make_unique? Using Visual Studio, it didn't suggest anything when I wrote std::make_unique, or make_unique or std::unique_pointer.
Anyway, could you provide an example instead?
[code] for (int i = 0; i < 9; i++)
{
sf::Vector2i tile = tileManage(i*20);
std::auto_ptr<Wall> wall(new Wall(tile.x, tile.y, "wall_brick"));
entities.push_back(&*wall);
}[/code]
this code gives me a 'access violation'-warning/error.
[QUOTE=proboardslol;46812618]Do Fourier transformations return the frequency of a sample? If I have. 1 sec 2400hz sample, will it return 2400?[/QUOTE]
They return the frequency distribution, so you'd still have to find the maximum and (in the case of real-world instruments) consolidate overtones into the fundamental.
Has anyone rewritten (or written something similar) SFML collision-detection?
This works nicely, but it only tells me whether they collide, not how/where they collide:
[code] bool BoundingBoxTest(const sf::Sprite& Object1, const sf::Sprite& Object2)
{
OrientedBoundingBox OBB1 (Object1);
OrientedBoundingBox OBB2 (Object2);
// Create the four distinct axes that are perpendicular to the edges of the two rectangles
sf::Vector2f Axes[4] = {
sf::Vector2f (OBB1.Points[1].x-OBB1.Points[0].x,
OBB1.Points[1].y-OBB1.Points[0].y),
sf::Vector2f (OBB1.Points[1].x-OBB1.Points[2].x,
OBB1.Points[1].y-OBB1.Points[2].y),
sf::Vector2f (OBB2.Points[0].x-OBB2.Points[3].x,
OBB2.Points[0].y-OBB2.Points[3].y),
sf::Vector2f (OBB2.Points[0].x-OBB2.Points[1].x,
OBB2.Points[0].y-OBB2.Points[1].y)
};
for (int i = 0; i<4; i++) // For each axis...
{
float MinOBB1, MaxOBB1, MinOBB2, MaxOBB2;
// ... project the points of both OBBs onto the axis ...
OBB1.ProjectOntoAxis(Axes[i], MinOBB1, MaxOBB1);
OBB2.ProjectOntoAxis(Axes[i], MinOBB2, MaxOBB2);
// ... and check whether the outermost projected points of both OBBs overlap.
// If this is not the case, the Seperating Axis Theorem states that there can be no collision between the rectangles
if (!((MinOBB2<=MaxOBB1)&&(MaxOBB2>=MinOBB1)))
{
return false;
}
}
return true;
}[/code]
I tried looking a the code, the only thing I can tell from it is:
collision left, down: when maxobb1 is bigger than minobb2
collision right, up: whenminobb1 is smaller than maxobb2
So I still can't see the difference between when objects collide right or up.
Any ideas?
[QUOTE=war_man333;46812455][code]
Wall w1(tileManage(0).x, tileManage(0).y, "wall_brick");
Wall w2(tileManage(20).x, tileManage(20).y, "wall_brick");
Wall w3(tileManage(40).x, tileManage(40).y, "wall_brick");
Wall w4(tileManage(60).x, tileManage(60).y, "wall_brick");
Wall w5(tileManage(80).x, tileManage(80).y, "wall_brick");
Wall w6(tileManage(100).x, tileManage(100).y, "wall_brick");
Wall w7(tileManage(120).x, tileManage(120).y, "wall_brick");
Wall w8(tileManage(140).x, tileManage(140).y, "wall_brick");
Wall w9(tileManage(160).x, tileManage(160).y, "wall_brick");
entities.push_back(&player);
entities.push_back(&enemy);
entities.push_back(&w1);
entities.push_back(&w2);
entities.push_back(&w3);
entities.push_back(&w4);
entities.push_back(&w5);
entities.push_back(&w6);
entities.push_back(&w7);
entities.push_back(&w8);
entities.push_back(&w9);[/code]
What's the efficient way of doing this?
tried doing this:
[code]
for (int i = 0; i < 9; i++)
{
sf::Vector2i tile = tileManage(i*20);
entities.push_back(&(Wall(tile.x, tile.y, "wall_brick")));
}[/code]
but I get a 'pure virtual function call'. What do I do?
Dunno if more code is necesarry to kill the problem, please do tell.[/QUOTE]
Smart pointers support polymorphism and own an object on the heap at the same time!
Emplace back is more efficient in that it creates an object right in the vector instead of copying an existing one like push back.
Emplace back's syntax is more elegant as well, allowing you to type in the constructor arguments right in the function.
[code]
std::vector<std::unique_ptr<Entity>> entities;
for (int i = 0; i < 9; i++)
{
sf::Vector2i tile = tileManage (i * 20);
entities.emplace_back (new Wall (tile.x, tile.y, "wall_brick"));
}
[/code]
[QUOTE=war_man333;46814983]I don't have anything called std::make_unique? Using Visual Studio, it didn't suggest anything when I wrote std::make_unique, or make_unique or std::unique_pointer.[/QUOTE]
Either get a more modern version of Visual Studio or simply include the <memory> header.
[QUOTE=war_man333;46815104]Has anyone rewritten (or written something similar) SFML collision-detection?
This works nicely, but it only tells me whether they collide, not how/where they collide:[/QUOTE]
I don't know what to say about collision detection. I've never worked with game engines before.
[QUOTE=elevate;46815130]Smart pointers support polymorphism and own an object on the heap at the same time!
Also emplace back allows you to construct an object right in the vector, instead of push_back which copies an already existing object into the vector. This is more efficient.
The syntax for emplace back is elegant as well, allowing you to type in the constructor arguments right in the function, instead of within a separate constructor call.
[code]
std::vector<std::unique_ptr<Entity>> entities;
for (int i = 0; i < 9; i++)
{
sf::Vector2i tile = tileManage (i * 20);
entities.emplace_back (new Wall (tile.x, tile.y, "wall_brick"));
}
[/code]
[/QUOTE]
Sweet! If you want to pass an element from this vector onto a method, what should the parameter be?
Like if I was to call:
[code]collisionPlayerMonster(entities[i], entities[o])[/code]
What should the parameters of collisionPlayerMonster be?
[code]void EventHandler::collisionPlayerMonster(first, second)[/code]
IntelliSense wants it to be [code]std::unique_ptr<Entity, std::default_delete<Entity>>[/code] but that doesn't work, and also seems like an odd type.
[QUOTE]Either get a more modern version of Visual Studio or simply include the <memory> header.[/QUOTE]
I got the <memory> included. 2012 rules!
[QUOTE=war_man333;46815185]Sweet! If you want to pass an element from this vector onto a method, what should the parameter be?
Like if I was to call:
[code]collisionPlayerMonster(entities[i], entities[o])[/code]
What should the parameters of collisionPlayerMonster be?
[/QUOTE]
[code]
bool collisionPlayerMonster (NPC* player, NPC* monster)
{
...
}
collisionPlayerMonster (entity[i].get (), entity[o].get ());
[/code]
Sorry, you need to Log In to post a reply to this thread.