Game Design, Programming and running a one-man games business…

Mip-Map hell with Production Line

In a recent conversation with fellow indies about how I can make production line look better, someone effectively said ‘why are you not using mip maps’, and at first I laughed because, LOL, I use mip maps, and then I remembered that the geniuses at Microsoft decided that D3DXSaveSurfaceToFile should not generate mipmaps so actually…the game didn’t use them for many of its props (the stuff in texture atlases, basically).

So obviously I immediately thought what a dork, generated mip maps and…

it kinda looked way worse. Or did I? I have stared at the pixels so much now I am starting to see things. Here is the game as it currently looks (mip maps enabled in engine, but most of the car graphics and prop graphics not generated with any). (click to enlarge)

And here is it with mip maps enabled. (click to enlarge)

From a distance does it look any BETTER to you? I’m not sure I can really tell much of a difference until I zoom in. Here is evidence of how blocky the current one looks when zoomed in…

versus the mip-mapped one.

Which obviously looks better, but its not *that* simple, because the mip-mapping also creates some artifacts. here is a montage of the current, and lots of mip-mapped styles, with different settings from mip map creation filters, sharpening and softening etc. I just can get those door lines to vanish…

Which possibly means that I need to adjust how those cars are being drawn, or means I have not yet found the perfect set of render options for generating dds mip maps. There is also the possibility that the way I render out my car-component atlases (with a black background) is bleeding onto the mip maps at lower levels, and that this is where the problem is.

Of course all of this is absolutely *a matter of opinion* and thus really annoying, as I am a data-driven guy and like hard facts,. so stuff like this is where I fall down a bit. I don’t like pixellated graphics ( I despise the look of minecraft) but on the other hand I also REALLY hate over-blurred images, which make me think my eyesight is failing or I need new glasses. Its also very tempting to give in to the mistake of zooming in to a static image and declaring the best one to be the one where a zoomed in screenshot looks best, which is WRONG because obviously when zoomed right in, the mip maps are irrelevant anyway. here is the current (non mip mapped) car zoomed in.

Which leaves me in a bit of a quandary. Is it even worth continuing to fuss over this stuff…does anybody really notice/care? Or should that time be better spent on adding new features to the game?

The case for buying tesla stock.

Yup, no games content here, just a brain dump of why I am so bullish (positive) about the prospects for tesla (Stock ticker: TSLA). Written in July 2019, 2 days before Q2 earnings release.

I own a Tesla model S, 85D AP1, from late 2015. Its the most amazing car I have ever owned. Its actually the most amazing *thing* I have ever owned, in terms of being so-far-ahead-of-the-competition-its-laughable. I smile every time I drive it, and I am *not* a car geek. I don’t know valves from torque from spark plugs. Here is my car:

In case you are unaware, Tesla is a US-based manufacturer of electric cars. They are the ONLY large company that is 100% dedicated to making electric vehicles. They are publicly traded on the new York stock market, and the CEO is Elon Musk (of spacex / boring company /t witter-personality fame). One interesting fact: despite widespread criticism by various old-school car company CEOs, as of this writing, Elon is the *longest serving CEO* of a major car company who is still in their job. So yup, he has more experience than the current GM/Ford/Nissan/Renault etc CEOs.

There are two strands to my case that Tesla is vastly undervalued as a stock (currently about $250). The first strand is the products, the second is the company. Lets start with the products.

The Tesla roadster is a now legendary car that by modern standards is kinda *meh*, but at the time proved something dramatic: you could make an electric car that accelerated and moved like a sports car and was FUN. Until then, electric cars were a joke. Slow, stupidly short range, unsexy, useless. The roadster changed all that.

The sequel to the roadster was the model S (I have one!) and it absolutely transformed everything. if you want to know how much, lets start with the fact that it recently got motortrends ultimate car of the year award, marking it as the most significant car in the last 70 years. Not the most significant sedan, or US car, or electric car, just the most significant CAR. No easy feat.

The model S has jaw-dropping stats coming out of its frunk. Mine is the relatively slow one (85D) that can only do 155mph and 0-60mph is 3.75 seconds. What a slouch. The current P100D with ludicrous mode does it in 2.275 seconds. If you aren’t into cars, a good comparison would be a car that does it in a slower 2.8 seconds such as this:

Thats a Lamborghini Aventador LP 750-4 SuperVeloce that retails at $493,000, slower than a Tesla model S costing about $135,000. If you are wondering why lamborghini is still in business, don’t ask me, I’m as confused as you are. Oh BTW the Tesla comes with autopilot, over-the-air updates and is an ELECTRIC car versus the gas guzzling monstrosity in orange pictured above.

So yup, they are fast, and thats amazing for an electric car right? but probably only go to the shops and back? A model S can go 528km NEDC rated without charging. So yup, no problem. I can just about drive my old, shorter range model from my house to London and back without charging (although I top it up at a service station when I grab a coffee anyway as its super convenient and free (early buyer!).

So the car is super fast, and super long range, but are they safe? can an electric car possibly be safe? Yup. Actually lets look at the safest cars in the world in a list.

Then lets check that yup…your car is way more likely to catch fire if its NOT a Tesla. Oh and youtube will show you a ton of crazy videos of how teslas autopilot software helps it to swerve (safely) out of the way of erratic drivers. Feel free to google for all the images of super harsh high-speed collisions that tesla drivers *walked* away from unhurt.

Thats the model S, the pricey one. they also have an even pricier SUV with unique ‘falcon-wing’ doors, called the model X, and they also have the smaller, and amazing looking model 3, which is about HALF the price of the model S. All are equally insane in terms of value for money, speed, acceleration, safety and range.

Normally, that would be the end of an impressive list of why the company has great cars…but there is so much more (and I don’t want to bore you). The cars have built-in video games (yes really), they have the largest touchscreens in any production car. They have an awesome mobile app you can use to pre-heat or chill your car. You can ‘summon’ your car out of the garage (opening doors as it goes) from your phone and you can control a whole ton of the cars systems using pretty reliable voice recognition.

Yup, as a product, the tesla cars are pretty much unbeatable. So thats one thing on our checklist, the company makes phenomenal products. But what about the company? can it sell any of these things? does anybody want them? will they ever sell them at a profit?

Tesla has had a lot of unprofitable years. A lot. It has basically plowed every penny it earns back into expansion, and not been afraid to raise money to fuel yet more expansion, yet a myth that circulates about the company selling cars at a loss is just flat out false. At the time of writing, Tesla automotive gross margin is 20.2%. Thats a PROFIT on every car by the way, not a loss. The reason the company has made an overall loss in many quarters is due to incredible, incredible expansion. Want to see how rapid:

As it grows, tesla is leaving every other car manufacturer in the world trying to make EVs in the dust. its almost embarrassing now. Take a look at this video: (skip to 1 minute 19 for the model 3s appearance)

Also note that this video is not up to date yet, the next few months show no signs of slowing down.

So yup…they are making a product that is selling well, and its apparently great, but does that mean they can keep up? what about the big established companies that actually know how to make cars…wont they crush tesla?

Well…they are not showing any signs of doing so. The Nissan leaf (version 2) has problems with charging twice in one day. The Audi etron has had battery-issues, and bragged about 20,000 pre-orders (versus 400,000+ for the model 3). The jaguar ipace has brake problems. Lexus is so hopeless they keep referring to their hybrids as ‘self-charging hybrids’ to trick people into thinking their gas guzzlers are EVs… The other companies… busy twiddling their thumbs and making vague promises, but certainly NOT producing EVs in large numbers, not even BAD EVs in large numbers. The market is being absolutely eaten by tesla, at least in the west.

So massive market share, profitable cars, critically acclaimed and no realistic competition… all good reasons to back a stock, but we haven’t even got started.

Teslas advertising budget is ZERO. Absolutely ZERO. And yet they are selling cars as quickly as they make them, so much so that they are opening a new factory (built in record time) in China (The first EVER fully-foreign-owned car venture to get permission for a Chinese factory) to satisfy demand in Asia. There is a long, sustained and incredibly well-funded campaign of FUD, lies and bullshit deliberately designed to kill off the company, and despite that, despite being a relative newcomer to the market, the company has grabbed market share at an unprecedented rate, PURELY by word of mouth. This last part is vital. I run a small business, I would KILL to have a product so good I could sell it without a single penny in advertising.

Want more? Well lets remember that this is a company that not only spends NOTHING on advertising, it actually sells its cars direct, cutting out any profit for ‘dealerships’. In some states in the US it is ILLEGAL to do this (land of the free huh?) and even so, people *cross the state line* to buy a Tesla, and then take it home. I’m not even kidding.

By the way, Tesla are the only EV company that has built its own global charging network. You don’t need to use one of those outdated, awful, slow, expensive generic chargers, you can use the tesla superchargers, charging at insane speeds, which the car will automatically route you to (and pre-condition your battery en-route to maximize charging efficiency). BTW the log-in and config process for the charger is…. you just stick the cable in the car and walk off. The system knows who you are, no passwords, no logins, no scanning…its seamless. Think there are only a few of these? think again…

And yet… despite the amazing products, super fast, super safe, super long range, super-selling, decent profit margins..we haven’t even touched on the long term prospects for the company. They have the best autopilot system in use today, and have a steam of serious experts working on full-self-driving. The market is skeptical about this (me too), but the changes of it amounting to NOTHING are minimal, and there is zero chance, given their billions of miles logged with semi-autonomous vehicles already, that *anyone* can beat Tesla to the ultimate self-driving car goal.

Waymo is stupidly valued at at least $30 BILLION, despite only offering self driving in a tiny part of a tiny town in a small state in a single country. This is INSANE.

So yup, lets round off this blog post with all the other stuff that is also going to propel this company at an astonishing rate…

They are working on electric trucks that look set to out-compete every conventional gasoline truck in the world (no small market). They are working on an electric pickup truck to compete very favorably in performance terms with the ford F-150. They are working on a super-car that makes the model S look practically sedate. They are working on solar roof tiles that look incredible, and ALL of these products have already been shown to the public.

Oh…and a new cheaper SUV/Sedan crossover (model Y) that is predicted to sell better than the 3/S/X combined.

Did I also mention Tesla energy, the company that built the largest battery on the planet? or maybe I forgot to mention maxwell technologies, the battery-tech company (that tesla just acquired) that gives tesla yet another incredible technological advantage over everybody else making car batteries.

Maybe I should note that the next generation of car buyers are overwhelmingly positive about tesla. They are the iphone generation, they understand touchscreens and plugging in devices to recharge them. They dont get excited about the smell of petrol engines or dream about doing oil changes. The tech generation wants products designed for them, not for their parents, and the only company in the auto space that even vaguely understands this is tesla. What other car company CEO has 27 million twitter followers? The prudish politicians, and ancient, bitter and angry old car company CEOs who criticize musk for smoking a legal drug have no idea that his target market aren’t shocked, they like the guy, and they love the cars. Nobody does this at a gig with a ford mondeo:

Frankly, looking at the share price of Tesla right now is hilarious. Its the biggest bargain on the stock market by a colossal margin. I’m looking forward to more and more people realizing that.

SCALE IT UP. SCALE! SCALE! SCALE!

I like the concept of scale. its why I’m obsessed with the ramp up of teslas gigafactory and car production, and why I am making a game about factories in the first place. I find factorio very impressive. I also find real world scale very impressive. Like REALLY huge wind turbines.

And REALLY huge solar farms.

So yeah… I like to address scale in my work (games!) too :D. I think that optimization and scale go hand in hand. its no good allowing players to create colossal factories if the option is only theoretical, given hugely slow code. So embracing scale FORCES you to write more optimized (i’d say ‘better’) code. I also think that in my tiny, tiny way, if I can get the CPU usage of my games down by just 10%, then thats a lot (high tens of thousands of players) of games running on PCs using less power. Thats good for the environment!

Anyway, on the subject of scale I just swapped my twin 27″ monitors for a single 49″ beast that weighs less and uses noticeably less power (yay progress!) and also way less cabling. I’m not sure I have the height just right yet, and it seems to tell some programs its a mere 3840 res and not 5120 res (which both my game, and many apps agree that it is).

First things first…. LOL huge monitors are awesome. I find myself daydreaming what it would be like to stick 11 year old me, used to playing pong on the CRT TV and stick him in front of a 49″ monitor with twin speakers & subwoofer belting out battlefield V. Its truly amazing. My 980ti cant quite handle a proper FOV in ultra resolution, so I may have to scale it down a little bit but hey…. its super fun.

This has led me to try out various games at that resolution including of course… Production Line! and it looks remarkably fun in 5120×1440 res (which it happily supports… (click to enlarge). BTW runs fine at 60fps with this map…

of course the target market for this is pretty small so far, but I definitely remember a time when the absolute maximum conceivable size for a monitor was about 1920, which is why loads of developers like me used to create 2048×1024 render targets, because obviously we wouldn’t need bigger (LOL), and TBH when I coded gratuitous space battles with 4096×2048 render targets for those show-offs with their fancy-ass 2560 res monitors, that again felt like a limit that *could never be crossed*, and yet here I am, in 2019 with a monitor that my own game from 10 years back (GSB1) now cannot quite cope with at 5120 res…

Scale in terms of coding to support silly monitor resolutions is one thing, but I also think its worth considering scale in other terms, such as users, bandwidth and so on. I doubt I will EVER make a game as successful as flappy bird, angry birds, fortnite or minecraft, but you have to wonder how many times devs got close to that and then kinda fell over (and failed to achieve their full potential) because they couldn’t cope with the scale.

Right now, positech has several obvious bottlenecks preventing us from coping if we suddenly had a mega hit (anything bigger than Democracy 3 probably). For one… I’m the only person doing customer support (yikes!), which means if you email support AT positech dot co dot uk and tell me the game doesn’t run on your linux toaster, its ME, the lead coder, lead designer, and lead biz-dev dude, who gets distracted by your email. Not ideal.

Another bottleneck is programming. Production Line is Windows only. I hate cross-platform stuff, but if the game suddenly sold 5x or 10x its current level, I’d be mad not to do an OSX port, and maybe IOS version (likely never linux…sorry but its way way too small). This would mean hiring someone to do a port, and the problem with that is it TAKES TIME right when you want to hit the zeitgeist with your hit game.

Because the costs of maintaining the infrastructure, both physical, and in terms of manpower, necessary for a mega-hit are so high, it makes zero sense for someone like me to really have it in place without a hit, although TBH I’m better prepared than most. My blog, website and reporting back-end is on a dedicated server, not some tiny VPS thing, and I have CPU time and bandwidth to burn.

The big problem (if I had a big hit and saw a need to scale) is that I’d need people FAST, and thats either hard, or expensive. If you live in downtown san fran, finding people is trivial, but their salaries are hysterical (due to property costs), so its swings and roundabouts.

I guess the sensible thing is to make sure you know WHO to talk to, in terms of outsourcing companies, and have made the contacts and pressed the flesh with them, without immediate plans, but with an eye to the future.

I guess I’m also saying that for companies that help with porting, or customer service etc, it makes sense to be polite and chatty and helpful to *as many indie devs as possible*, so that you are on speed-dial for them when their 16th game goes to #1 in the steam charts.

Maybe Democracy 4?

How to 10x your indie game development process

Oh yes, I know all about search engine optimization. Can you tell?

I talk to a lot of indie devs, although TBH not as many as I would like to, and I find many of the discussions illuminating. Because I work mostly alone in a little room in a field in the shire, I get so used to my way of doing things that its easy to forget there even are other ways. However, one of the most illuminating things is discovering just how long it takes most developers to do things (whether its code, art, biz dev, production stuff, whatever), and I am constantly shocked at how my output seems to not be 20-30% higher than many devs, but seemingly 300-400%+ more than many developers.

This blog post will try and explain how.

Its harsh. This is not touchy-feely happy cliff. This may annoy you, and make me seem a harsh, competitive, aggressive workaholic. This is reality. Most people don’t want to know this reality, but they claim to want it. This will not motivate everyone, but here goes…

Tip #1 Stop fucking around with ‘fun’ disguised as work.

Reading reddit is not work, unless its 100% actual new, informative, well-reasoned and argued and productivity or sales-boosting information directly applicable to indie game development on the platform/genre combo you work in. Reading about how to make mobile games about ponies is not going to improve your bottom line when you are a PC strategy game developer, no matter how much you kid yourself it will.

This also includes playing a dozen new indie games a month, or watching youtube lets plays or twitch streams of a whole bunch of new games. Thats not ‘market research’, its just goofing around. If you are currently between titles, and thinking seriously, and doing market research into industry trends etc, then yes, MAYBE you can claim a few hours for doing this as ‘work’. If you current game design is pretty fixed, and you are > 6 months away from release, it really doesn’t matter a fuck what is #1 in the indie game charts and how it plays. Thats not work. It will NOT change your immediate plans, don’t pretend otherwise.

Tip#2 Work somewhere quiet.

No a coffee shop is not quiet. Nor is any room in your house/apartment where other people walk through regularly. You need to be an end-zone where people only enter your room if they need YOU. Unless the house is literally on fire, someone has been shot, or imminent death or suffering beckons, nobody should disturb you when you are working. Nobody. You are in isolation. Don’t kid yourself that ‘you work better in a gregarious group of chatty people’. Thats crap and deep down you know that.

Tip#3 Get a big monitor, get 2 big monitors. Don’t feel bad if you have 3.

You cannot get a lot of work done on a tiny laptop. Thats silly. its 2019. Get some big monitors, they are cheap. I have twin 27″ monitors at 2560×1440 res. I couldn’t work at my current rate with less. I spend less time alt-tabbing than you. I can glance at my inbox without a context switch from game dev. I can view loads of my code and my game at high resolution at the same time. Monitors are cheap. its a business investment. Trust me. Buy 2, big, high quality ones. Buy them now.

literally the bare minimum

Tip#4 Shortcut keys and batch files etc

I feel physically pained when someone right clicks and selects ‘copy’ or ‘paste’. How many shortcut keys do you know? Copy & paste & cut and select word, select line, select page up + down? Windows + R Windows+F? Alt+tab? Shift+alt+tab? Windows+arrow keys? Know them all. You actually do not need a mouse for much. the mouse is SLOW. I use batch files to process files in photoshop quite a lot. I also know a lot of shortcut keys in textpad32 and paintshop pro. Also… if you use visual studio are you using visual assist? its amazing. use it. USE every productivity tool imaginable. leverage what computers are good at. Get a fast PC.

I know devs who use zipped up files and drag-dropping to back up their code. FFS. Use source control and cloud backup software that automates all this for you. If code and software exists to make you more productive USE it. Use email filters and rules. So much time-saving software exists, use it.

FFS I even have my living room lights come on automatically at sunset without me pressing buttons. Automate the fuck out of things.

Tip#5 Comfort

You will work longer and harder and happier in a nice work environment. When it comes to my office, no expense is spared. If you are an indie developer, your desk and office chair are probably more important to you than your car, TV, cooker and sofa combined. You will (hopefully) spend a lot of time in that chair at that desk. Get a really good one. try many, the really good ones will last a while. Mine is an aeron, 9 years old, still perfect. I actually had a desk made for me (surprisingly cheap actually), It will last forever. Do not make false economies here. Mine was about £800. Thats under £100 a year so far for the place I park my ass most of my life.

other chairs are shit

Tip#6 Mindset

If you are working on your first game, I hate to be that ‘one guy’ who breaks with the happy-clappy hugs and flowers online twitter group hug, but no, you are not an indie game dev, you are a wannabe. You are trying. you might one day release a game, in which case, well done, welcome to the club. the world is littered with people who try and fail, and those who give up. Someone who is ‘working on a novel’ is not a novelist, they are a hobbyist.

If you want the warm glowy feeling of being an indie dev who entertains people and ships games and makes a living from it, they you need to work hard as fuck, for a long time, and get your head down and get the product shipped. Do not surround yourself with well meaning people who tell you what you want to hear. Thats a route that spirals down and down into insular failure and disappointment. If your game is behind schedule then you are failing. Stop whining and work harder, and keep that attitude until you finish something.

Also… don’t kid yourself that you have worked ‘super hard’ because you put in a solid 6 hours work at your desk today. Thats great, but frankly someone flipping burgers has worked longer and harder than you today. You claim to want to make a secure living in one of the most competitive, sought-after, cut-throat industries in the world? Well so does everybody else. Most people fail. Most people lose. You will not make a success of this working less hours than someone doing an unskilled minimum wage job. Do not blame me for the harsh realities of competition, but more importantly do not pretend they don’t exist because that truth is inconvenient.

This job is not hard. You want hard? go work as a soldier, a police officer, as a trauma surgeon or an astronaut. game dev is fucking easy. Don’t kid yourself.

Tip#7 Focus on one thing well

If you are good at making 2D RPGs, make 2D RPGs. Unless you have three years salary in the bank, and a lot of confidence, and are absolutely MISERABLE making those games, do not change. Every 2D RPG you make improves your skills, your experience, your audience, your engine, your productivity and your tool-chain.

I’m a competent programmer. I could make a 3D physics game next. Maybe I have a cool idea for one, but for fucks sake that is a BIG leap away from 2D/iso strategy/management games. Why throw 90% of my audience, experience, skills and technologyonto a bonfire just to switch genres and styles.

You might decide to change genres/engines/languages etc because you are seeking artistic fulfillment. Thats great, but thats the luxury of a leisure activity. Again…3 years salary banked? go for it. Else…thats almost certainly a poor business decision. Get good at a thing, then do that thing until its a big success. There is HUGE opportunity cost when you learn a new genre/style/language/technology. Make sure you are fully aware of this. Few genres are so small they cannot support a single indie dev.

source:spiderweb software, experts in genre focus

Tip#8 Seek out harsh but real criticism

I get a fair few really good reviews and emails from people who really like my games. I love them. they make me feel happy, and warm, and appreciated and other nice things. its a good feeling. They don’t actually make my games better though. The emails you hate, the negative reviews, the dreaded steam refund reasons… these are the harsh angry truths that you do NOT want to hear, and yet you must. When someones tells you ‘i could make a better GUI with my ass whilst high‘, you may be angry, depressed, furious, insulted…but you need to hear it. maybe your GUI *is* bad. Maybe it could be improved.

to be fair, that slider was really crap. its better now.

Do not insulate yourself from the negative. negativity can lead to change, improvement and accomplishment. Data about what you are doing badly is absolutely essential in improving. If nobody ever tells you your games art direction is shit, or your game title is stupid, you will never improve it. If you *absolutely* cannot cope with harsh, hurtful criticism, then you probably should not try to make a living from indie game development.

Tip#9 avoid chances for distraction

I used to use rescuetime. I also used to use an hourglass to focus myself on work. I now find I need neither. I’ve worked so hard, so long, I’ve internalized what they used to do for me. Most people aren’t at that stage, and they get distracted. if your phone distracts you from work, switch it off. Nothing will explode. We survived thousands of years without mobile phones, you will be fine for entire eight hour stretches. You don’t need twitter during work hours, you don’t need to check the news sites or reddit during work hours.

If your code takes time to compile or art takes time to render, learn to multi-task with other WORK stuff. Set aside small tasks, like replying to forum threads, easy tech-support emails etc, so you can do them when you are waiting for your work to complete. Schedule other activities that you need to do anyway around times you know you are waiting for your PC. I mow the lawn/chop firewood while my PC renders out youtube videos for me. If my PC needs to reboot and update the O/S I will set it off before I have lunch, or last thing at night.

Avoid situations where your PC is sat there doing something (rendering / compiling / updating) and you have nothing to do but SIT THERE. You will get distracted, your mind-state will collapse, your productivity will plummet.

source: XKCD

Tip#10 Avoid bullshit productivity planning admin

Some peoples reaction to stuff like this is to immediately start planning to be more productive. they will start a productivity planning spreadsheet, with nice formatting, some color-coding and even a company logo, or they will google for inspirational quotes to print out and then stick up around the office. or they will start making an important list of the top ten things they have learned about productivity. They might hop onto discord to chat to fellow devs and share their new found enthusiasm for productivity with their buddies…

This is all bullshit.

The true response to this blog post, which is ending very shortly, is to close your browser. (yes CLOSE it), and do some work. Internalize the *attitude* not the specifics, and actually DO something. In other words, do not become like this classic, absolutely on-topic sketch from the life-of-brian which does a great job of showing exactly what I’m on about.

Get back to work and stop fucking around.

Starting the game: An in depth profiling look

How long does your indie game take to start up? from clicking the icon to actually being able to take input at the main menu? Just for fun, I decided to analyze whats involved in doing so for mine.

Because the aim here is to actually analyze the REAL impact, not the best case, I need to ensure that the game (Production Line) is not just happily sat there all in RAM from a recent run-through, so it seems best to oh…maybe launch battlefield V beforehand (and quit it) just to populate disk/RAM with a load of other stuff and do my best to evict all my games code.

Then…its time to fire-up aqtime and take a look. I decided to do line-level, rather than just function-level analysis, which slows the game massively, taking 17 seconds to start (the reality is dramatically faster), but I can still do relative comparisons.

First thing to notice is that pretty much the entire time is inside Game::InitApp() which makes sense.

Rather worryingly though, the vast majority appears to be inside SIM_Threadmanager::Initialise. That *may* be an artifact of aqtimes approach to thread profiling, but worth taking a look inside anyway… And it turns out that 100% of that time is inside SetThreadName() (which i only need for debugging anyway). This is a rare bit of code that I don’t understand well, and was from the evil interwebs:

#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
	DWORD dwType; // Must be 0x1000.
	LPCSTR szName; // Pointer to name (in user addr space).
	DWORD dwThreadID; // Thread ID (-1=caller thread).
	DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)

void SetThreadName(DWORD dwThreadID, char* threadName)
{
	THREADNAME_INFO info;
	info.dwType = 0x1000;
	info.szName = threadName;
	info.dwThreadID = dwThreadID;
	info.dwFlags = 0;

	__try
	{
		RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), 
(ULONG_PTR*)&info);
	}
	__except (EXCEPTION_EXECUTE_HANDLER)
	{
		volatile int foo = 9;
	}
}

The exception is basically ALL of the time. WTF? Apparently there is a less hacky way outlined here: https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code?view=vs-2019 Which I will try later. I suspect the waiting for visual studios debugger is the cause of the problem.

Anyway…onwards and upwards, so whats next? It basically all Init3D() (click to enlarge)

So basically my DirectX initialisation and the shadermanager stuff is most of the problem. I suspect the DirectX initialisdation may be too black-boxed for me to influence further. The first big chunk is this line:

PD3D9 = Direct3DCreate9(D3D_SDK_VERSION);    

Which takes up 34.74% of the start time. The next slow bit is the largest at 41% which is:

hr = PD3D9->CreateDevice( AdapterToUse, DeviceType, WindowHandle,
 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &PresentParameters, &PDevice);    

So…holy crap. how can that line of code even be run? This can only happen if my checkcaps() code suggest the video card does not support hardware transform and lighting. I suspect some of the reporting here must be nonsense? Especially as my own debug logs suggest that the hardware TNL version is the one than ran… FFS :( lets look outside that code then…

Most of the slowdown is in shader manager, which loads 11 shaders:

so it looks like about half the loading time here is actually spent writing out debug data! This is hard to avoid though, as I do find this data invaluable for detecting errors. And because an app can crash and lose all its data, I flush each line of my debug logs to disk with a hard drive flush on each line…

…so interestingly all the time seems to be inside OutputDebugString, which is only of any real use when the debugger is running. However! I *do* want to see that data in both release builds, and debug builds. Maybe I need a flag to tell if a debugger is present when the debug engine starts up? As a first pass I should at least build up a char* with the newline in to avoid twice the OutputDebugString calls. Here is the new code and timings.

Ooooh. I’ve halved the time of it. I’ve done the same with my non-directx debug code too. Now I’ll try changing that thread stuff… It turns out that SetThreadDescription is windows 10 only, so I need a different system (and apparently would need to update my platform SDK…urrrgh), so maybe best to just skip calling that code when no debugger is detected?

This works (using isDebuggerPresent) but the profiler actually trips that flag too, so to set it work I needed to compare time stamps on debug files. Without the debugger, it looks like time from app start to menu ready is 0.395 seconds. With the debugger its… 0.532 seconds.

That sounds pretty small, but actually I’m quite happy as I lost ZERO functionality, and the changes to the debug data will affect any time that data is written, not just during startup. 9Its not a lot, but there is *some*, and I’m an efficiency obsessive.

I think I’ll put a clause around the debugengines OutputDebugString and nuke that unless IsDebuggerPresent() too :D