Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 29 Jul 2010
Offline Last Active Mar 31 2014 04:51 AM

#5085121 Object Composition and Getter/Setters

Posted by on 12 August 2013 - 01:58 AM

"AConnection->SetDataBufferSize(size)" is not the same thing with "rawData->SetBufferSize(size)".

The former is the public interface, and the later is the internal implementation.


Today your Connection::SetDataBufferSize forwards to DataBuffer::SetBufferSize, tomorrow you may change to that your Connection::SetDataBufferSize invokes some complicated logic other than DataBuffer::SetBufferSize. Nobody cares the changes as long as the public interface is the same.


So, I don't think there is any problem with your "setter" chain.

#5080307 Game engine editor design

Posted by on 24 July 2013 - 08:23 PM

You should better build your editor upon your engine. Such as, your editor uses the animation system in your engine to animate the objects in the editor.

That has two benefits:

1, You don't repeat yourself.

2, Using engine in your editor may help you to find defects in your engine.

The easiest way to use your engine in your editor is, write your editor in C++.

Qt is a good choice, and so wxWidgets.

#5019783 Goto and Loops - NOT a goto discussion

Posted by on 10 January 2013 - 12:09 AM

As far as I understand (same as others), that should be invalid syntax. Variable 'I" should be only valid in the for loop.

Also, even it's valid syntax, I would never write that kind of code because it's so confusing. Indeed I would not spend my any time on studying "goto". I will stop here, otherwise will bring a flame war of "goto" discussion.

#5011470 C++ arbitrarily sorting a struct

Posted by on 16 December 2012 - 08:29 PM

if(a.dir > b.dir) {

    return false;


if(a.startx > b.startx) {

    return false;


if(a.starty > b.starty) {

    return false;


return true;

Not sure if it's want you want.
My code returns true only whan a's all fields are less than b's

#5009689 Java game Garbage Collection

Posted by on 11 December 2012 - 10:01 PM

You should avoid frequently allocate/free objects, e.g, allocate a lot of objects in each frame.
Instead, allocate some objects before entering the level and reuse them until the level is finished. That's some kind of "cache" or "pool".
Also, check if you have a lot of string "add" operation. S3 = S1 + S2 will cause dynamic memory allocation, IMO.

#5008970 New Class made -> error LNK2019: unresolved external symbol

Posted by on 09 December 2012 - 09:40 PM

EDIT: Never mind, I see the problem, I shouldn't have initialized it as City Ice_Palace_City() -> But Ice_Palace_City.

Stupid mistake!

Not that stupid.
That's another C++ quirk.
When defining an object value, if using default constructor, we can't write the "()" because it will be treated as function declaration, but if not the default constructor, we have to give "()".
MyClass obj; // can't have ()
MyClass obj(1, "abc");

#5008964 New Class made -> error LNK2019: unresolved external symbol

Posted by on 09 December 2012 - 09:16 PM

Please show your code, especially the error related function/class.

#5008034 4D Arrays?

Posted by on 07 December 2012 - 02:15 AM

If you don't know what is in a 4D array, why do you bother to make a 4D array?
Also, when we come to a multiple dimension array, especially so high dimension 4D, we should consider better data structure rather than a plain array.
So if you want to store X, Y, Z, D in a 4D array, how about store them in a 1D array with a structure.
struct Item {
int X;
Item myArray[100];
Isn't that clearer?
If you are not using C/C++, just make Item a class.

#5007997 Irrlicht any good?

Posted by on 06 December 2012 - 10:54 PM

Most likely you will choose between irrlicht and ogre.
Goolging "irrlicht vs ogre" without quote marks will give you a bunch of comparison. You need to check which one will satisfy all your needs.

I didn't use both engine, but I compiled Irrlicht and it's super easy to compile with VC. Also Irrlicht has plenty of wonderful sample code. Not sure about OGRE.

#5007746 Read/Write binary

Posted by on 06 December 2012 - 07:27 AM

vertices = new TextureVertex[numVertices];
buffer.read((char*) vertices, sizeof(TextureVertex) * numVertices);

No &, because vertics is already the address.

#5007006 Smart pointer casting

Posted by on 04 December 2012 - 02:19 AM

Seems you are implementing your own version smart pointer, then you should implement your own version of static_pointer_cast, dynamic_pointer_cast, and const_pointer_cast.

You can dig into Boost source code to see how its smart pointer doing that.

Also, since you are writting C++ code, you'd better adopt the "long" caster operators. Longer line is OK, losing type safe with C style cast is not quite OK.

#5006960 Running a LUA script one part at a time

Posted by on 03 December 2012 - 10:00 PM

Pseudo code, you must polish it...

Lua code
function taskA()
    TextOut("Hello I am a monster")
    Wait("A", 5)
    TextOut("Now I'm going to eat you")
    Wait("A", 2)
    TextOut("Yum yum")
function Wait(what, period)
    CppWait(what, period)
function resumeA()
-- main code
coA = coroutine.create(taskA)

C++ code
void CppWait(std::string what, int period)
    // add period to some condition list by "what"
void YourGameLoop()
    if(condition for taskA is met) {

Hope the code explains itself.
Note: I never used Lua coroutine before...

#5004915 unique_ptr private member

Posted by on 28 November 2012 - 04:21 AM

IsLevel1Atlas's parameter is a value of unique_ptr, you can't copy a unique_ptr.
Change IsLevel1Atlas to
auto IsLevel1Atlas = [](const std::unique_ptr<Atlas> & atlas) -> bool { return atlas->GetName() == L"Level1Atlas"; };

The first one works I guess your list::push_back must implement rvalue reference (&&) version?

#5004454 A problem about a pointer to member function?

Posted by on 27 November 2012 - 03:02 AM

So going off the above, (this-> *fn) ends up meaning this->visit, which is the same as just saying visit.

I think -> * should be ->* because it's a single operator and we can even overload it.

OP, try to Google for "c++ pointer to member operator", no quote mark.
Here are some search results,

And Hodgman's reply. :-)

#5004381 A problem about a pointer to member function?

Posted by on 26 November 2012 - 08:07 PM

void (MyClass::*visit) (int,int)