Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

413 Neutral

About Daivuk

  • Rank

Personal Information

  • Interests
  1. Daivuk

    Beginner - DirectX and C++

    For inputs you have 2 options: Listen for WM_KEYDOWN and WM_KEYUP events. Use Direct Input. (my recommendation). it is keyboard agnostic so WASD will be mapped to the same keys even on AZERTY keyboards. Google around for Direct Input tutorials.   If you need text input, don't use neither of those. use the WM_CHAR event.
  2. Loading resources or map data asynchronously in games is not an easy task. C++11 makes all of this a lot easier. I am going to demonstrate how to create a thread using async. And then how to sync back to the main loop using lambda functions. Consider the following code, that is blocking: void onNewGame(){ // Load the map loadMap("level1-1.map"); // Start the game startGame();}void loadMap(const std::string& in_filename){ // ... Do extensive work, freezes the screen for couple seconds.}Lets start by adding the loading code into a thread. Using std::async. #include // This is the include for asyncvoid onNewGame(){ // Load the map, asynchronously std::async(loadMap, "level1-1.map"); // return and continue normal execution... render your animated loading screen on your mainloop}void loadMap(const std::string& in_filename){ // ... Do extensive work}That was easy? Now we need to notify the game when the loading is complete. By calling "startGame()" in our example above. This is not as easy as it sound, because the loadMap() function is now running on a different thread. You could set an atomic boolean, and check it every frame. But then we will end up with specific cases all over the place. What we want is to synchronize with our main loop. Consider the following typical mainloop: void mainLoop(){ while (true) { game.update(); game.draw(); }}If we were to set a global atomic bool, we would probably put it like this: void mainLoop(){ while (true) { if (mapLoadingDone) { startGame(); mapLoadingDone = false; } game.update(); game.draw(); }}And mapLoadingDone is a boolean that would be set to true at the end of loadMap(). Lets do this a bit more generic. Let's modify our loadMap() first: void loadMap(const std::string& in_filename){ // ... Do extensive work // Notify that loading is done syncToMainLoop([]() { startGame(); });}Simple function call, with inline code block. This is called a lambda. In previous C++ or C, you would have to define a function and pass it as pointer. Now lets see the implementation of syncToMainLoop. #include #include #include std::queue syncQueue;std::mutex syncMutex;void syncToMainLoop(std::function in_callback){ syncMutex.lock(); syncQueue.push(in_callback); syncMutex.unlock();}The std::function is the new way of doing function pointers in C++. The queue is used to pile up multiple sync request in case multiple happen during a single frame. The mutex is there to prevent the queue from being accessed in multiple places at the same time. Now we just need to add this to the main loop: void mainLoop(){ while (true) { // Do the sync requests syncMutex.lock(); while (!syncQueue.empty()) { auto callback = syncQueue.front(); // Get the next in line callback(); // Call it syncQueue.pop(); // Remove it } syncMutex.unlock(); game.update(); game.draw(); }}Now you can sync back to the main thread during any async loading. Here is the full code of the example: #include #include #include #include std::queue syncQueue;std::mutex syncMutex;void mainLoop(){ while (true) { // Do the sync requests syncMutex.lock(); while (!syncQueue.empty()) { auto callback = syncQueue.front(); // Get the next in line callback(); // Call it syncQueue.pop(); // Remove it } syncMutex.unlock(); game.update(); game.draw(); }}void syncToMainLoop(std::function in_callback){ syncMutex.lock(); ?syncQueue.push(in_callback); syncMutex.unlock();}void onNewGame(){ // Load the map, asynchronously std::async(loadMap, "level1-1.map"); // return and continue normal execution... render your animated loading screen on your mainloop}void loadMap(const std::string& in_filename){ // ... Do extensive work // Notify that loading is done syncToMainLoop([]() { startGame(); });}
  3. Daivuk

    (Super) Smart Pointer

    We call this a "Weak Reference". I don't have examples at hand, but that's the term you want to search for   Edit: What BitMaster said. std::weak_ptr
  4. Exactly, this is the purpose for the original question. It seems that this GL Hint does 'magically' fix it.   I highly doubt OpenGL can fix this also.   The hint is called "PERSPECTIVE". Which means it doesn't work for 2D. It needs the z (depth) value to calculate this correctly. In 2D no such things. The GPU can not know the context of that triangle in a 2d environement. And doesn't understand it is a quad at low level.   If all 4 points have the same z value in your 2D render (let say, 0), and GL gives you the right picture, then the driver or opengl is wrong. What about I want to skew a rectangle on the side?
  5. Daivuk

    A good engine for GameDev...

    If you don't want to do a lot of coding, like you say. And you already know C#. Then Unity3D is your choice.   XNA is certainly enough to make interesting games. Tons of games on Steam use it. And I did pretty amazing stuff with it.   I'm personally not a big fan of "Engines" per say. I prefer having a set of libraries that do certain jobs for you: Load images, draw fonts, do inputs, etc. Like SDL or SFML. Then you build the "game engine" around it.
  6. Daivuk

    Questions for all programmers.

    1) What was the first programming language you studied? QBasic in DOS   2) Did you have any Computer Science background before your first language (ie: boolean algebra, memory organisation, algorithms)? No   3) The first language you studied was it self-taught, formal instruction, or both? Self-taught   4) Was the Computer-Science background self-taught, formal instruction, or both? Self-taught   5) When you started to study Computer Science did it help your understanding of the language you first learned? I never studied Computer Science. But my game programming courses didn't help much as I had already learned everything by myself. But my background helped me get good grades.   6) What kind of environment did you first program in (ie: the IDE or text editor, and the OS)? QBasic had it's own text editor in DOS
  7. As a concrete example of why they are bad:   I am using Cocos2dX for a project. And we had to send network call. Great, cocosx provides a client HTTP built on top of Curl. It's a singleton class (Which means a global var basically) with most of its variable static or globally declared in the CPP. It didn't cause problem at first. Everything is queued when I make multiple call. Ok, perfect.   But then, we started to want to send some calls simultaneously. LIke uploading a file in the background, but continuing navigating in the app.   But we can't, because there is only 1 instance of the HTTP client! And we can't instantiate another one, because everything is static in it. And they even had global vars in the CPP!! A design that sounded good at first ended up a nightmare. I was able to remove the static vars and globals. I can now create multiple instance of the class.   It's a good example I believe. Also if your game end up supporting multiplayer or split-screen. If all you have are static, you will be in hell. (Been there also)
  8. Daivuk

    Managers, which pattern should I use

    Singleton pattern is the most commonly used for managers. Just careful to not put managers as singleton that don't need to be.   One day you will want to add multiplayer, or split screen, to your game. And all those singleton will haunt you. Some things, like Texture manager, should definitely be in a singleton. It's sharing textures across all part of the engine.   But input manager, maybe not. If you add a second controller for player 2, you might want him to handle his own input separately, and you will want a second instance of input manager.   What I do in my games generally, is create a global singleton, where I put all those managers in. Globals::getInstance()->textureManager()->getTexture("baby.png"); Globals::getInstance()->inputManagers[PlayerId]->isButtonDown('A');   Not the best practice, but accessing things easily from everywhere is nice too. Also I cant keep all my other managers singleton-free.
  9. You are going to have to create a font, load it, display it.   Take a look at bmfont: http://www.angelcode.com/products/bmfont/ Some tutorials are included on the site.
  10. The way to do it is not to thread rendering and updating simultaneously, but instead threading operations that cost a lot before proceeding to next operation. Instead of threading big modules against each others (update, rendering), thread the tasks into those modules. Update() Thread all entities' physic. wait that they are all complete Thread path finding. Like calculating path for 4 units at the same time, in 4 different threads? (i.e.: if 20 paths to calculate, split evenly 5 in each threads) wait that they are all complete Thread the next big job wait the threads for that job are complete. Render() Thread the culling of all entities Wait that culling is done computing. Maybe thread the swap buffer to start updating the next frame? (It might stall there to wait for vsync, you could update next frame during that time!) I did that in a game we did and it worked greats, we gained speed on lower spec PCs. It's a more intelligent way of using threading in games. And also what I like to do, is count the number of cores/processors available and use that as the number of threads to start for each big jobs.
  11. Daivuk

    What is Microsofts problem?

    Having developed on every platforms and most of the consoles/devices out there. I find Visual Studio the best IDE that exists. It has its problems, but its still the best in my opinion. Only bad thing about it personally is the intellisens. And if your employer is too cheap to buy you a licence of VisualAssist (My case) then it's a bit troublesome. But I never had problems with libraries dependencies and I've used them a lot. Not sure what you are talking about? XCode was a nightmare to work with in my case. I guess it's a matter of taste/experience with one more than the other. Very bad post tho. I believe Microsoft cares more about its developers than its concurrents. Giving Android as an example is a very bad example. Just try to code a C++ app on android. That was a hell of a nightmare with not even a STL implementation. Same things goes as Xbox dev vs PS3 dev, etc. Microsoft always win as developer support and softwares.
  12. We did pretty well with BaboViolent2. It is multiplayer only, we don't even support bots. And we still have a pretty big player base at the moment, 4 years later. I think if you do it right, and have a place where the community can grow (Forums, etc) and a good way of listing / joining games. You will get your player base pretty quickly. Now the problem is, to keep it! [color=#1C2837][size=2] players you have will quickly abandon ship[/quote] [color=#1C2837][size=2]This was exactly what happened with our "Madballs in... Babo: Invasion" game. The player base was high for some weekends after a sale, but then went go down and then people will say: Game is good, but the multiplayer is empty! Luckily we added a single player campaign to it. [color=#1C2837][size=2] [color="#1c2837"]I think you just need to make a game that feels right and people don't get bored too fast. And mostly: Competitive. That is the key, otherwise player base will disappear quickly.
  13. Daivuk

    Adding sprint ability - how?

    [color="#1C2837"][font="CourierNew, monospace"][color="#666600"][color="#666600"]**** GAMEDEV PLZ FIX THE COPY PASTE THAT CREATES JUNK KTHXBAI ****[/font] [font="CourierNew, monospace"] [/font][font="CourierNew, monospace"][color="#666600"]I had to edit that post 4 times... [/font] [color="#1C2837"][font="CourierNew, monospace"] [/font] [color="#1C2837"][font="CourierNew, monospace"][color="#666600"][color="#666600"]I would do that:[/font] [color="#1C2837"][font="CourierNew, monospace"] float moveSpeed = 1; if (mKeyboard->isKeyDown(OIS::KC_RSHIFT)) {[/font] [color="#1C2837"][font="CourierNew, monospace"] moveSpeed = 2;[/font] [color="#1C2837"][font="CourierNew, monospace"]}[/font] [color="#1C2837"][font="CourierNew, monospace"]if (mKeyboard->isKeyDown(OIS::KC_A))[/font] [color="#1C2837"][font="CourierNew, monospace"]{[/font] [color="#1C2837"][font="CourierNew, monospace"] strafe = -moveSpeed;[/font][/font] [color="#1C2837"][font="CourierNew, monospace"]}[/font] [color="#1C2837"][font="CourierNew, monospace"] [/font] [color="#1C2837"][font="CourierNew, monospace"]Ok, I just can't get the code snippet to show up correctly :@[/font] [font="CourierNew, monospace"][color="#1C2837"]Here is the non formated version:[/font] [font="CourierNew, monospace"][color="#1C2837"]float moveSpeed = 1;[/font] [font="CourierNew, monospace"][color="#1C2837"]if (Right shift down)[/font] [font="CourierNew, monospace"][color="#1C2837"]{[/font] [font="CourierNew, monospace"][color="#1C2837"] moveSpeed = 2; // What ever speed you want[/font] [font="CourierNew, monospace"][color="#1C2837"]}[/font] [font="CourierNew, monospace"][color="#1C2837"]if ('A' is down)[/font] [font="CourierNew, monospace"][color="#1C2837"]{[/font] [font="CourierNew, monospace"][color="#1C2837"] strafe = -moveSpeed;[/font] [font="CourierNew, monospace"][color="#1C2837"]}[/font] [font="CourierNew, monospace"][color="#1C2837"]...[/font]
  14. [font="Arial"]Is an MS in Mathematics enough to break into graphics? Yes[/font] [font="Arial"]Do you need a MS to break into graphics? No[/font] I have only a college degree in game programming, and I am Lead Graphics Programmer today. Only what I needed was linear maths, and LOT of experience in Rendering. I did some integrals and such in college, but doesn't remember much about it. I find myself limited sometimes in the understanding of certain papers. So it would surely help to have a MS. Depending what branch of graphics you are going: Medical, research, gaming. For gaming you just need the basics, clear understanding of matrices and shaders. Because the most complex things you might have to achieve are SSAO and deferred rendering. The other complex rendering techniques are mostly for research and show off demo. Not for actual games. Unless you are aiming the top (EPIC Games, Crytek...)
  15. Daivuk

    C++ Classes Question

    I tend to agree with @[color=#2B3730]nfries88. When a project gets very big, compile time becomes a big issue. By using pointers, you can use forward declaration. We should do that as much as possible, unless you do not have other choices to not use pointers.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!