Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


nimrodson

Member Since 13 Feb 2012
Offline Last Active Aug 23 2013 06:33 PM

#5050656 Traversing a List of Vectors

Posted by nimrodson on 06 April 2013 - 02:13 PM

If you're using C++11, you can try this too:

 

#include <vector>
#include <list>
#include <iostream>

int main()
{
  std::list<std::vector<int>> listVectors{{1,2,3},{4,5,6},{7,8,9}};
  for ( auto& vec : listVectors )
    for ( int& i : vec )
      //process each int i
      std::cout << i << std::endl;
}




#5048952 Three of a kind numbers

Posted by nimrodson on 01 April 2013 - 02:20 PM

Just for fun, a (beginner) Haskell implementation:

 

unique :: (Eq a) => [a] -> [a]
unique []     = []
unique (x:xs) = x : unique (filter (\y -> not (x==y)) xs)

nOcurrences :: (Eq a) => a -> [a] -> Int
nOcurrences elem list = length (filter (==elem) list)

isThreeKind :: (Eq a) => [a] -> Bool
isThreeKind list = elem 3 [nOcurrences i list | i <- (unique list)]

You could parametrize the 3 number in "isThreeKind" function and have a "fourKind", a "fiveKind", or whatever...

Cheers.




#5048034 Object was not declared in this scope?

Posted by nimrodson on 29 March 2013 - 10:39 AM

When you doing this:
 
 

// creating the object
if(event.button.button==SDL_BUTTON_LEFT) bullet myBullet(90, 530, 20, -20, 1);

 
You're using *automatic* (EDITED, thanks @rip-off. Don't confuse with "auto" C++11 reserved word) declaration -> allocation on the variable "myBullet". That means (among other things) that the "myBullet" timelife remains in the scope in which that variable was declared, in this case, the precedent if statement. When the if statement is consumed, all the *automatic* resources inside the "if" scope are destroyed, including "myBullet". That is the reason why "myBullet.update()" is undefined, because there's no declaration of "myBullet" in the present scope or an outter scope (When you comment out the first line, myBullet declaration, this is in a outter scope, and therefore works). 
What you need to do is using dynamic allocation, something like the solutions presented by the others members.


#5048024 What is functional programming and how can it help us in game developing?

Posted by nimrodson on 29 March 2013 - 10:19 AM

Using compute shaders is functional programming. Functional programming and associated languages usually map better to hardware (think FPGAs) than software. Come to think of it, any shader is a functional program evaluated simultaneously on blocks of data.

 

OK, thanks for the tip. But, what happens in a higher abstraction level? Which elements of functional programming could be beneficious in game design?

 

Newly, thanks. 




#5047852 What is functional programming and how can it help us in game developing?

Posted by nimrodson on 28 March 2013 - 09:29 PM

Hi,

 

I would like to know some opinions about this programming paradigm: It is useful? How much? Could have an important role or participation in game design and/or coding? It is complementary, opposite, or totally uncomparable to OOP?

 

Thanks. 




#5028518 What is the difference between "Entity" and "Sprite"?

Posted by nimrodson on 03 February 2013 - 09:04 PM

Just that. Thanks.




PARTNERS