Jump to content

  • Log In with Google      Sign In   
  • Create Account


Wooh

Member Since 19 Dec 2008
Offline Last Active Yesterday, 05:32 AM

#5168877 This singleton keeps crashing.

Posted by Wooh on 24 July 2014 - 09:03 AM

<stdint.h> is part of the C standard library, not the C++ standard library. While most compilers allow you to include their C includes from C++, they are not required to do so (nor do they even have to have C includes somewhere to be standard compliant).


This is what the C++11 standard (Appendix D.5) says about it.
 

For compatibility with the C standard library and the C Unicode TR, the C++ standard library provides the 25 C headers, as shown in Table 154.

Table 154 - C headers
<assert.h><inttypes.h><signal.h><stdio.h><wchar.h>
<complex.h><iso646.h><stdalign.h><stdlib.h><wctype.h>
<ctype.h><limits.h><stdarg.h><string.h>
<errno.h><locale.h><stdbool.h><tgmath.h>
<fenv.h><math.h><stddef.h><time.h>
<float.h><setjmp.h><stdint.h><uchar.h>




#5165075 how to use or ||

Posted by Wooh on 06 July 2014 - 11:20 AM

Do you run this code repeatedly while the sound is playing?


#5164349 iterator output not in sync

Posted by Wooh on 02 July 2014 - 10:22 AM

Not sure if you missed my reply or maybe I was not clear.

Each time you call next() you will get a different element. In your code you are printing the x of the first element, the y of the second element and the z of the third element. In the next iteration you print the x of the fourth element, the y of the fifth element and the z of the sixth element. And so on.

To print the x, y and z of the same element you should only call next() once in each iteration.

while (vecIterator.hasNext()) {
	vector3D v = vecIterator.next();
	System.out.println("iterator list output " + v.x + " " + v.y  + " " + v.z);
}



#5164242 iterator output not in sync

Posted by Wooh on 02 July 2014 - 01:09 AM

The problem is that each time you call next() you are stepping the iterator to the next element.


#5129797 LAN: Is it bad practice to use broadcasting to send all data?

Posted by Wooh on 08 February 2014 - 03:41 AM

Thank you for all your opinions. I have decided to use UDP broadcasting only to find the other players. I think this will allow me to reuse a lot of code if I choose to implement playing over the Internet in the future. Only the code to find and connect to other players would have to be different.


#5081437 arguments

Posted by Wooh on 29 July 2013 - 06:38 AM

You can use c_str() to get a const char* from a std::string but that pointer will only stay valid for as long as the string is not destroyed/modified.

const char* ss = (*it2)->toString().toStdString().c_str();
doSomethingWith(ss); // ERROR: The data pointed to by ss is no longer valid.

If you just want to pass it to a function on the same line it is OK because the string has not yet been destroyed.

doSomethingWith((*it2)->toString().toStdString().c_str()); // OK

If you want to use it on more than one line you could store the string in a variable to extend the lifetime of the pointer.

std::string str = (*it2)->toString().toStdString();
const char* ss = str.c_str();
doSomethingWith(ss); // OK
doSomethingElseWith(ss); // OK

If you want a non-const char* you can use &str[0] instead of str.c_str().




#5081425 arguments

Posted by Wooh on 29 July 2013 - 05:50 AM

std::cout << (*it2)->toString().toStdString() << std::endl;

Not sure if it's the best way to do it but I think it will should work.


#5076561 PNGs with transparency in SDL.

Posted by Wooh on 10 July 2013 - 02:44 AM

You are passing the wrong format to SDL_MapRGBA. screen->format should be img1->format.

When you set the alpha value for each pixel you are ignoring the alpha values that the image was saved as so you will see pixels that are not supposed to be seen.

To not destroy the original alpha values you could draw to the screen surface directly. If you change alpha to a floating point type and slowly change it from 0 to 1 and do something like this inside the loop
*screenPixel = SDL_MapRGBA(screen->format, r, g, b, a * alpha);
I think you will get the effect you want.

Another way I thought would work was to set the per-surface alpha value using SDL_SetAlpha but that doesn't appear to work.


#5071106 Return reference from assignment

Posted by Wooh on 19 June 2013 - 06:56 AM

In C++ you can do
int T;
Method(&(T = 5 + 5));
but I don't think that is possible in C.


#5065367 std::bind and function

Posted by Wooh on 27 May 2013 - 05:24 PM

The say function doesn't do anything. Use std::cout if you want to print the string.
void say(){std::cout<<"I'm foo\n";}



#5065157 decltype

Posted by Wooh on 27 May 2013 - 12:13 AM

I think the class types that you use in the tuple has to be defined and not just forward declared.


#5064502 SDL.net

Posted by Wooh on 24 May 2013 - 09:12 AM

If you know how TCP and UDP works you can probably read most things from the SDL_net documentation (warning: the description for SDLNet_TCP_Recv is wrong/misleading).

As for your problem it's hard to know what's going on. You mentioned package so I assume you are using UDP. How do you notice that it doesn't work. Do you get an error or is it just that the other side never receives what you sent? You know that UDP packages are not guaranteed to arrive?


#5064497 C++ create an array of nested class objects in a class

Posted by Wooh on 24 May 2013 - 08:50 AM

You should only delete what you have created with new.

Is mcaTroops supposed to be static, meaning it only exists one such array that will stay alive until the end of the program, or do you want each GenObjectClass to have its own mcaTroops array?


#5064470 [JAVA] What if I don't define the toString() method?

Posted by Wooh on 24 May 2013 - 07:13 AM

If you don't define toString() it will be inherited from Object, that defines it as
getClass().getName() + '@' + Integer.toHexString(hashCode())



#5064431 C++ create an array of nested class objects in a class

Posted by Wooh on 24 May 2013 - 04:32 AM

You don't need SetupObj(). The objects in the arrays will be created when the array is created.




PARTNERS