Jump to content

  • Log In with Google      Sign In   
  • Create Account

Josh Petrie

Member Since 11 Jun 2003
Online Last Active Today, 07:43 PM

#5294170 How to set a namespace properly in this case?

Posted by Josh Petrie on 30 May 2016 - 09:59 AM

A static lib I could build of course, but my core code does change once in a while. That would be something I do once I have everything really stable.



That's fine; just create a .vxcproj that builds the static library and include that project in your solution as well. You may find this guide on MSDN useful for getting set up.

#5294092 How to set a namespace properly in this case?

Posted by Josh Petrie on 29 May 2016 - 06:46 PM

I was worried that it might be a little too slow to call a Render or update function through a pointer. Especially since all my rendering is done in software. I'm probably still going to keep it like that since there's no penalty like with other methods.



If that ever becomes the bottleneck in your code, you're in pretty excellent shape. It will not be an issue.


Just because it's faster. You said I can just use subversion or something and sync the base code into a new project? 



What you're doing is unlikely to be faster. It will be, at best, on par. It's likely to actually be slower in practice, if for no other reason than you are compiling the code for all your games all the time, especially when you change common header files.
I'm not suggesting you use Subversion (I mean, you should use version control in general but that's a whole different subject). Rather I'm suggesting you use your IDEs built-in functionality to create different projects and create dependencies between those. Instead of creating one project in which you re-invent your own method of doing what the IDE can already do better.
For example, if you're using Visual Studio, you have a solution file (whatever.sln). A solution file can contain multiple projects (.vcxproj files in the case of C++); you have at least one by default. You're trying to put everything in one .vcxproj and do some unusual preprocessor/lexical/language "tricks" to switch out which game you're building, running and debugging.
But you can also create more .vcxprojs. You can create one .vcxproj per game. On the disk, you organize your code like this:
  - source code for your common utilities, "engine" functionality, et cetera -- anything that would be shared -- goes here
  - Asteroids.vcxproj
  - source code specific to the Asteroids game goes here.
  - Breakout.vcxproj
  - source code specific to the Breakout game goes here.

Each .vcxproj can reference the common code and include it all. But within VS, you can set any individual project to be the "startup" project, which means that's the one it will build and run when you hit F5 (or whatever). 


For bonus points you'll want to actually create a project that builds your common code into a static library and have the rest of game projects link against that, because manually referencing the common source code in every project becomes cumbersome fast.


This gives you a way to have multiple games, sharing code, in one solution and switch between them trivially without having to actually modify any of your code... and it's the way the rest of the world accomplishes this task. Even if you don't use VS almost every IDE worth using has a similar set of functionality.

#5294074 How to set a namespace properly in this case?

Posted by Josh Petrie on 29 May 2016 - 03:18 PM

So this structure in general is not ideal? My original goal was to try to avoid use of classes and encapsulation just as an experiment, so my code is very C-ish. I find that it's very flexible as the engine doesn't have to be in a single class or file but I just rather have a collection of functions that I can use at any point in the framework. That is why I chose not to use interfaces. 


It's definitely not ideal. It is very clunky, brittle, and unorthodox.
Further, the ideas that code can be encapsulated, be "C-ish," and be in a single file... those are all completely orthogonal, separate ideas. Nothing about having one implies a requirement to have the other. That said, you can do the same thing in pure C:
struct GameFunctions {
   void (*UpdateFunction)(float);
   void (*RenderFunction)(float);

int main () {
   GameFunctions functions;
   functions.UpdateFunction = &AsteroidsGame_Update;
   functions.RenderFunction = &AsteroidsGame_Render;

   while(!done) {
or similar.
I still don't really understand your desire to avoid actually putting separate projects in separate projects. 

My previous structure was a little different but I found this one in a book and thought it would be more straight forward. The previous structure was as follows:



Namespaces are basically a red herring here. You can do exactly what you are trying to do without using them, and it will be simpler.

PS. How can I share the code tree with multiple projects? (VS 2015)



If you don't have it on GitHub or similar, you could .zip it and upload it. 

#5294058 How to set a namespace properly in this case?

Posted by Josh Petrie on 29 May 2016 - 11:15 AM

You can't write a "using" declaration for a namespace the compiler has not yet seen, and by the time the compiler is seeing the preprocessed WindowsMain.h you haven't declared the NameOfGame namespace. Do something to declare that namespace (even if it is empty) above WindowsMain.h:

// NameOfGame.cpp
namespace NameOfGame {};
#include "WindowsMain.h"

That said, this seems like a rather backwards approach as it requires what appears to be a general-purpose, library header (WindowsMain.h) to know something about the game-specific code that is consuming it (NameOfGame). It also requires a very specific and somewhat unorthodox code structure. There are definitely better ways at both the IDE level and the C++ level to handle this.


At the IDE level, you can pretty easily put multiple projects in a single solution (or multiple targets in a workspace, etc etc for whatever terminology your IDE of choice uses). Those multiple projects can share the same common source tree, except for their game-specific parts, or statically link to common functionality built into a library.


At the language level, you can write your main windows driver (main() or WinMain() function) to instantiate and use a Game object that implements a specific interface (e.g., IGame, where all your required entry points from WindowsMain.h are currently defined). Then, even if you don't want to go the route of creating multiple projects in the IDE, you can simply switch the game you run by changing main():

int main (...) {
   AsteroidsGame actualGame; // Change this to BreakoutGame or whatever to switch.
   IGame & game = actualGame; // illustrating interface only, not actually needed.

   return game.run();

You get the same result without the brittle nature of the technique you're trying to employ right now. I still don't think it's a great idea (you still have all that other code for other games sitting around and getting potentially rebuilt all the time), although you can alleviate some of the weirdness further with macros and preprocessor tricks. Really should just learn how to use multiple projects at that point though.

#5293606 Are Third Party Game Engines the Future

Posted by Josh Petrie on 26 May 2016 - 09:35 AM

a team has full control over how an internal engine changes or evolves but do not have the same control over a third party engine.




Not necessarily true. It's quite possible to get full-source licenses to several popular pieces of middleware, including Unreal. At that point you can do anything you want, generally (including not take further updates and evolve in whatever direction you choose).


One could make the argument that it's still harder because you didn't write the code and so you don't know it as well as code you'd write in-house, but it's usually pretty easy to learn, and that argument washes out as soon as the internal engine gets old enough that the original authors of pieces of code leave the company.

#5292512 Best gaming platform in the future with marketing perspective.

Posted by Josh Petrie on 19 May 2016 - 10:27 AM

I think this discussion of the pros and cons of various Microsoft products, services and strategic decisions is veering a little too far off-topic at this point.

#5292391 how can i use the CreateTimerQueueTimer()?

Posted by Josh Petrie on 18 May 2016 - 07:01 PM

i must use the CreateTimerQueueTimerWT_SET_MAX_THREADPOOL_THREADS() or i will get errors on lValue, like i said before.



That's because the macro is intended to modify the flags value given as the first parameter. It's not a function, its a textual substitution of an expression that performs and |= on the flags value. Don't treat it like a function. Call it like Wyrframe does in the above post.

#5292312 how can i use the CreateTimerQueueTimer()?

Posted by Josh Petrie on 18 May 2016 - 11:53 AM

only these function give me several problems.

and the macro is wrong:


because don't return the result... so i did:


The macro is not wrong. Macros are not functions, they don't need to "return" their results. They are textually-substituted into your source code. Use the macro, don't write your own function to replicate the macro because all you're doing is creating a future bug for yourself when the macro changes but your function didn't.

#5292304 Building a Portfolio

Posted by Josh Petrie on 18 May 2016 - 10:31 AM

As a programmer, the value of your portfolio comes from the challenges you face completing those projects, and specifically from the interest technical conversations you are able to have about how you approached those challenges. One-versus-many projects is less important than one-versus-many challenges, although all else being equal I'd focus on one project instead of many because you'll be able to produce something more complete, cohesive and polished. "Fitting everything together" like you need to in a finished project is an important skill, and one that doesn't get exercised as much when you make many smaller projects, as you'll just skimp on that aspect.


I'd caution against a story-driven RPG though. "Story driven" implies a lot of time building content, and when you apply as a programmer the focus is not going to be on your storytelling skills or your ability to design a bunch of interesting dungeons. These may be advantages, yes, but you have to consider how you want to spend the time on the project. More time solving interesting technical challenges, which you can then discuss at an interview to show off your problem-solving ability and approach to handling new things, is probably better.


Most importantly, make something you want to make. Don't make something explicitly to be a "portfolio piece." It will show.

#5292293 New to Game Development, and don't know where to start.

Posted by Josh Petrie on 18 May 2016 - 09:36 AM

One option is to pick a programming language and start learning it. Python or C# are good choices for first languages.


Another option is to pick up a tool like Game Maker, or a high level engine like Unity or Unreal, and start learning that.


Learning to program will take longer, and you'll spend more time focusing on the basics of programming by building text-based console mode games. In contrast, learning something like Unity or Unreal will let you get started much faster building fairly complicated graphical games. But you will ultimately need to learn some sort of programming or programming-like logic thinking in order to really customize and tailor what you can do with those engines.


It will largely be a matter of how much instant gratification you need to satisfy your creative interest. I would personally recommend you dedicate a few days to trying to learn Python and making a simple text-based game like "guess the number" or hangman. Then switch gears and spend a few days trying to build something simple in Unreal or Game Maker. Think about which you enjoyed more and go from there.

#5292182 Need mentorship from a veteran programmer

Posted by Josh Petrie on 17 May 2016 - 06:36 PM

...in one or two short paragraphs, talk about your challenges while developing, talk about bottlenecks and how you solved it, talk about the late nights. Talk about a few "eureka" moments you had and how elated you felt when you had your current break throughs and the challenges you are still working on. Talk about what you expect for the future and your vision as a programmer if you were given the chance to join that great company. Talk about your ability to work well in a team (try to keep it short though so your resume would still be of reasonable size)



It's a good idea to note what was challenging or interesting in the point-by-point breakdown of what you did on a project, but what you're describing here sounds more like what would be on a cover letter in the US, not on the resume itself.

#5291968 What does a C++ Programmer need to get the job?

Posted by Josh Petrie on 16 May 2016 - 05:01 PM

While age discrimination certainly exists, it's not a widespread problem in the industry. What I'm trying to get at is really the futility of trying to generalize too much, you can find people with pretty much every view (positive or negative) of every fact about a candidate. Thus, trying to bend over backward to make some fact true or false about yourself in the hopes to achieve better results in an interview isn't always worth it. It can be a gamble.

What somebody sees as a risk will be different from person to person and situation to situation. An "uneducated" 25 year old may be a risk because he or she may not know what they're doing (too junior for the position in question). Somebody starting a career later or making a transition from another career (that is, somebody older) may be a risk because they have higher salary expectations than the budget can afford. Et cetera

#5291948 timeSetEvent(): can i change the timers limit?

Posted by Josh Petrie on 16 May 2016 - 03:23 PM

- the interval between frames(animated gif's) can be diferent;


You can trivially account for this if you build your own timer callback system. Also, you really should not be using this to trigger frame switches for animated pictures and the like; it doesn't really scale. Cursory investigation around the internet suggests the limit you're running into is something like 12 to 16 active timer events.
- i can't use CreateTimeQueueTimer , because i can't put it to work... only errors or don't starts:(


You absolutely can use it; what you mean to say is that you don't know how or can't figure it out, because you get errors. Perhaps if you asked that question and provided those errors somebody could help.


- the timeEndPeriod() is always called, depending on timerid value.



You're right, I didn't see it the first time through. This is still a very unusual use of the pair, since you call it for every timer, but really you only need to call it once. Windows always uses the highest resolution (lowest value) provided to it through this call. You're not setting resolutions on a per-instance basis here.
i don't know use WT_SET_MAX_THREADPOOL_THREAD. what i know is that it's a const, nothing more i know


The documentation linked for CreateTimeQueueTimer explains how to use it. It's a macro, not a const variable. And it only works with CreateTimeQueueTimer, since it evaluates to a value you pass to that function's flags parameter.

#5291943 What does a C++ Programmer need to get the job?

Posted by Josh Petrie on 16 May 2016 - 03:17 PM

3. A bigger company means there are more people to learn from, what to and not to do which depends on how many of them are talented in their roles. Also potentially higher job security with a company that is fiscally secure. I was laid off from a company last year that had less than 15 employees because they couldn't afford to keep me. When I get laid off I like to know it is because the position is no longer needed, not that they are broke as fuck cause their games bring in very little money. So when I am making a name for myself, yea I'd like to start as a face in a crowd.




This isn't always true though. It's good that you know what you want, but don't make the mistake of thinking that it's only a big company that can provide these things. For example, it's also common for large companies to suffer more from silo effects, where each team is kept rather isolated. This means even though the company has hundreds of thousands of employees you're practically or actually limited to interacting with five or ten on a regular basis anyhow. Similarly, larger does tend to mean more financially stable... but that doesn't mean financial stability for you. In a larger company, it can also be easier to lay off entire swathes of people. Including you.




4. Okay. Although to me it is more a matter of me wanting to lower the perceived risk associated to me from an employer's point of view.

You see I would much rather attend university to learn about earth sciences, physics, and mathematics. In my opinion I could just as easily learn CS on the job from others and through simple practice of my craft, as I could learn by going several more tens of thousands of dollars into debt.



You can get a job without a degree. At 28, you're basically "screwed" either way, risk-wise. Somebody will look at you and say "he's a risk, he's 28 and has no degree." The next person will look at you when you get done another four year degree and say "he's a risk, he's 32 and looking for entry-level work." So go back to school if you want to, but I'd recommend against doing it just because you think it's going to improve your job prospects in four years.


Companies that relocate any and all full-time employees do exist (larger companies, which you seem to want, are especially more likely to be able to do this). You can usually find out pretty early on in the interview process, so it does not really hurt you to try to start applying to places you want to work on the west coast now and see what happens.

#5291940 timeSetEvent(): can i change the timers limit?

Posted by Josh Petrie on 16 May 2016 - 03:05 PM

You probably should not be using timeSetEvent for this. Not only is it deprecated, it's got limitations like you're running up against that are hard to control. The function that replaces it is CreateTimeQueueTimer. It's possible timeSetEvent is running into the same threadpool worker limit described therein, in which case you can perhaps adjust it by using WT_SET_MAX_THREADPOOL_THREAD, but this has potentially significant implications and probably isn't the best idea.


You may be better off driving your timer system off a custom implementation based on your game's high resolution update timer, as it will be more flexible.


Note that you also have several bugs in this code related to concurrency potential (your timer count update is unguarded and your timer ID assignment is based on it, both of which can cause bugs such as incorrect counts or duplicate timer IDs) and use of the time* APIs (you call timeBeginPeriod every time a timer starts, potentially overriding the previously set global resolution if its lower, and you never call timeEndPeriod. You must match each begin call with an end call that provides the same period value, per the documentation.