Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Member Since 04 Jan 2013
Offline Last Active Private

#5198771 constructor for class that contains another class and constructor C++

Posted by wintertime on 17 December 2014 - 09:16 AM

I personally dont like having vector classes derive from each other in that way. A 4D vector is not a 3D vector, its more like the 3D vector is a special case of the 4D vector.
Its easy to add a conversion constructor for cases where you really want conversion without needing inheritance and prevents loosing w silently.
Additionally, the natural form of a vector is IMO an array, not a struct. This allows indexing and cuts down on repetition from having getX, getY, getZ, getW, getU, getV, getR, getG, getB, getA, ...

Btw., why dont you use a premade library like glm or others?

#5198201 C++: Easiest way to implement an in-game Time/Date system?...

Posted by wintertime on 14 December 2014 - 04:22 PM

As for converting to milliseconds etc...
I currently add the time difference to a boost::posix_time::ptime object in milliseconds, so my function for getting ticks looks like this:

	QueryPerformanceCounter( &count );

	QueryPerformanceFrequency( &freq );

	return ( LONGLONG( 1000 ) * count.QuadPart )/freq.QuadPart;
Then I add the result of the difference between 2 readings, multiplied by interpolation, to the displayed time. There's nothing wrong with that, is there?

That is so wrong. The multiplication could overflow and you are wasting precision by converting too early.
Always keep the ticks as long as possible, subtract 2 tick values to get the time difference, then only on last moment before using the value for drawing convert it to milliseconds.

#5198102 30k concurrent players on a (private) MMO server...is this possible ?

Posted by wintertime on 14 December 2014 - 04:57 AM

In Ragnarök Online ground, walls, houses, trees and such are actually made of 3D. There are many hills (which are a good reason to prefer 3D), its relatively low-poly and you can sometimes find cracks revealing it.
Just the camera is rather restrictively fixed and you can only be rotated around your character, zoom a bit and change its angle slightly (that is one of the many things I heared some cheaters have hex-edited away). This is to hide that the server only sends data for characters and skill effects inside a square for about 14 tiles distance from your character (which can be seen when tilting the camera and looking downhill or having a widescreen monitor).
Monster, NPC, Characters and their accessories are 2D sprites though.
I've seen fights of 2-3 allys of 2-4 guilds per ally of 30-56 people each guild, all squeezed into 2 or 3 screens of space. Problems start when all are spamming skills up to 4 times a second (they made the mistake of including a 2 minute area spell reducing cast times and skill delays for everyone inside), which are often area spells that get send per tile. Then the server is struggling, its discarding skill effects revealing holes, discarding skill commands, queuing move clicks for too long and ultimately disconnecting everyone lagged more than a minute, sometimes silently making the client hang, all while the monsters whack away at the player characters.
Additionally, rumours are going around the server is not optimized well.

Therefore more than 16-32 people per map should certainly be possible for your game if done carefully enough.

#5197965 How should i call my classes instead of "xyManager"?

Posted by wintertime on 13 December 2014 - 06:39 AM

I try to be a bit more accurate, there is not that much functionality in the ImageManager.
It has an Init function, which load the textures to a container, and have a function like that: sf::Texture getTileTexture     (Image::TileTexture texture);
Which give back the given texture (TileTexture is an enum)
So it does 2 things: Load the textures, and give an interface to get the texture you need.

You didn't tell you were using a library like SFML, which is doing most of the work already. Internally SFML has a number of classes already interacting to provide that functionality, including Texture, Image, some loader wrapper and stb_image doing actual loading and decoding.
You may not only want to give back the texture (and its important to use a reference, do not return it by value), but also give back an sf:Rectangle for the texture coordinates of a tile when one texture contains a whole tilemap. Maybe call it something like TileTextureFinder.

No, these classes just iterate through all Units and Buildings, and call the update on them. Everything else is done by the given Unit's or Building's update function.

There was a recent discussion on another thread that you should not have a single loop calling a magic update, as that can cause inconsistencies from objects accessing old state from one object and new state from another. Have separate functions doing input, movement, drawing and so on, then add a loop for each kind of functionality.

#5197951 How should i call my classes instead of "xyManager"?

Posted by wintertime on 13 December 2014 - 05:38 AM

The manager name comes from putting too much global functionality into a single class. Its a good idea to follow the Single Responsibility Principle and have each class only be responsible for one job.

Just to give an example, in extreme case you could split the ImageManager into TextureCache, TextureUploader, Texture, ImageCache, ImageDecoder, Image and reusable FileCache, FileLoader, MemoryBuffer and MemoryAllocators, though most likely this is way too much.

Building and UnitManager seem to have no clear purpose, you could just use some reusable templated container class and add functions in the relevant subsystems doing work on the whole container.

EventManager I would skip, too. A Queue without any special functionality (besides thread safety if needed), where you put in Events, will do for a while.

#5195690 30k concurrent players on a (private) MMO server...is this possible ?

Posted by wintertime on 01 December 2014 - 07:25 AM

RO-players are often bragging and exaggerating things - he was probably speaking of 300, not 30000.rolleyes.gif

The game got inefficient TCP networking and IIRC doesnt even set the nodelay option. Its well known that an official server (actually a server-cluster) would hold about 2000-3000 people, in exceptional case 8000. And if there were more than 200 on a single mapserver in WoE it started lagging, at about 250-300 moves could take a minute until the server reacted, skill commands would be ignored and people would get disconnected constantly from CPU-overload. I remember a company licensing the game apologised for the constant lag and thereby admitted the game was so inefficient that even though they bought the fastest machines available (although they got told their old machines were good enough which they coudnt believe) it did not help much.

I doubt the server emulator I heared the pservers were using was much more efficient and even more, there would never have been that many people on an illegal pserver.

#5193681 [4X / TBS] Diplomacy...

Posted by wintertime on 19 November 2014 - 03:22 PM

In Alpha Centauri you could send a unit into some other players territory, who then gets the option to ask you for retreat for violating his territory, and then you get the option to accept and get the unit teleported back or have a vendetta started. I think thats a good mechanism to prevent "peaceful" invasions blocking someones territory with the only options of staying eternally annoyed at it or having the role of agressor attached to you, when the other party actually started this and then possibly the senate denying you even that when your state was a republic in Civilization.

#5192962 Proper C++ header file?

Posted by wintertime on 15 November 2014 - 04:36 AM

For a proper header file you should not include a bunch of files you do not need. Only add them if you cant forward declare a class and prefer having the include in the cpp file, but minimize these, too.

And use descriptive names where you dont need to guess if, for example, loc is location (cant be, a string location is weird?), lines of code(uhh no, why?) or something else.

It would be good to learn about how to use const references and the constructor initializer list, to see how these prevent useless copying.

Try following the "tell, dont ask" principle and only add get/set methods if you cant replace them by methods that do the real work inside the class. The remaining one-line-methods could then be put into the header so they can be inlined.

#5192839 Live filesystem changes

Posted by wintertime on 14 November 2014 - 07:14 AM

Just get an account on https://bitbucket.org/ and make a repository! You can have unlimited free private and public repositories and choose between git and Mercurial.

If you dont change the same file at same time a merge is mostly going automatically anyway and much safer than you both constantly having to endure a broken build as the other is typing in more code that gets synchronized too early.

#5191658 Novice C++ programmer, looking for ways to create art for game and such

Posted by wintertime on 07 November 2014 - 07:09 AM

This guy does some decent tutorials, its all vector graphics, pretty much focused towards programmers smile.png



This is what I thought of telling, too. He got so many nice tutorials on http://2dgameartforprogrammers.blogspot.de/ and I think its much easier to create something good looking using a tool for making vector graphics ( Inkscape ) compared to tediously doing pixel graphics by hand-choosing colors for single pixels.

#5189080 a problem with opengl and glfw

Posted by wintertime on 25 October 2014 - 08:54 AM

Put -lopengl32 last, not first, because the linker does not know other libraries depend on it before having worked on these.

Also it would be better to not use glu, its outdated and there are better ways of setting the projection and getting mipmaps made.

And you should order the constructor initializer list in the same way as the class members, fix the bug with the access to the uninitialized variable and fix the setting thats not recognized.

#5188297 Reading PNG format (deflate compression)

Posted by wintertime on 21 October 2014 - 06:38 AM

I think you would learn more about png image format (as compared to deflate compression) if you just use zlib and concentrate on the other bits of the format at first. Later you can always add on your own deflate decoder, after being able to decode all png chunks including all registered ancillary chunks.

#5188217 C++ Serialize OpengGL pixel data in bitmap formatted byte array

Posted by wintertime on 20 October 2014 - 06:26 PM

Looks like you read the pixels as RGB although .bmp is in BGR, which you could get from OpenGL, too.

#5184945 Questions on first Win32 windows application

Posted by wintertime on 04 October 2014 - 08:02 AM

1. That stems from their confused sense of Unicode and a wrong thinking of needing to keep compatibility with ASCII.

Read http://utf8everywhere.org/ on how to better handle this!

2. Sometimes its needed as a function parameter, but there is also another function to retrieve it if you dont have it.

3. Its a callback you provide, only the function address matters and you can choose any name you like for it. Under some circumstances it may be even useful to have more than one.

4. There are a countless number of messages that get put into a queue, which you there retrieve with GetMessage and pass along to Dispatchmessage, which internally calls your callback function. When clicking the x all kinds of mouse messages get through first and then when the click is confirmed you get a WM_CLOSE, to which the typical response is calling DestroyWindow, which sends the WM_DESTROY and there you call PostQuitMessage, which sends WM_QUIT, which should make your message loop exit from a special return value from GetMessage. Its all pretty complicated and thats why most messages you are not interested in are forwarded to DefWindowProc, which is like your window procedure, but premade for default handling.

5. You cant just add a magic number to a (hidden) pointer and expect the program to still work. Read up on what alternative values you can provide to change it.

#5171148 Need Help with amortization formula

Posted by wintertime on 02 August 2014 - 12:01 PM

Why dont you ask your teacher (thats his job) how function parameters work, how return values are used, how to find descriptive variable names and how to translate a formula into a C++ function?