Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 Jun 2000
Offline Last Active Yesterday, 09:05 AM

#5316660 A quick way to determine if 8 small integers are all equal to each other

Posted by on 25 October 2016 - 02:52 PM

My favourite quick-prototyping tool for deciding whether or not a code rewrite has the intended effect on what the compiler produces:


Frob's loop code: https://godbolt.org/g/HEFMYz


Frob's manually unrolled code: https://godbolt.org/g/MZrQRH


JonnyCode's obfuscated XOR trickery: https://godbolt.org/g/3UAbN5


I'll admit that what JonnyCode's written is what you want, if you want a constant-time algorithm (which is something you want in some algorithms, to prevent a certain class of cryptographic attack)... but as you can see, the transformation from "do what I mean" code to the less-readable "do what I say" code does not have a noticeable effect on total instruction count or (admittedly eyeballed) clock cycles. In the worst case scenarios, there's just as many register/ALU round trips, and there's just as many fetches made.


But as Khatharr says, as will every other developer worth his salt: you don't know where the actual time is being spent in your algorithms until you profile it. Even when you guess correctly, it is only a guess. Analysis of evidence is more valuable than analysis of theory.

#5316110 Moving from plain "ascii" to XML?

Posted by on 21 October 2016 - 01:20 PM

http://yaml.org/ , in particular, yaml-cpp. From their example/tutorial:

YAML::Node config = YAML::LoadFile("config.yaml");

if (config["lastLogin"]) {
  std::cout << "Last logged in: " << config["lastLogin"].as<DateTime>() << "\n";

const std::string username = config["username"].as<std::string>();
const std::string password = config["password"].as<std::string>();
login(username, password);
config["lastLogin"] = getCurrentDateTime();

std::ofstream fout("config.yaml");
fout << config;

#5315575 C++ : Extend class in dll

Posted by on 17 October 2016 - 12:41 PM

A slightly more concrete example, which also walks through the differences between the naive and mature approaches...



#5314985 What is the general name for types like Quadtrees and Octrees etc

Posted by on 13 October 2016 - 09:01 AM

Know that there is also Kd-trees. It's like BSP, but you don't store a vector-per-split; you just store a magnitude. Each split's axis is determined from its depth in the tree, modulo the number of dimensions, e.g. the root node splits on the X axis, the next level splits on the Y axes of the two X parts, the next level splits on the Z axes of the four Y parts, and the next level splits on X again. Ideally you want to split an equal number of elements to either side of each split.


The main advantages over BSP as a spatial search structure (as opposed to BSP's main uses in the 90s as a spatial *traversal* structure) is that the tree is easier to build, and there's no vector math involved to test which side of a split a point or object is on, only axis-aligned-bounds checks.

#5314861 What controller to use while developing PC game

Posted by on 12 October 2016 - 09:26 AM

As a sim enthusiast... making your game support an xbox-for-windows controller is nice and entry-level and low-barrier-to-entry and all... but please, please, if your game has even remotely sim-like complexity or gameplay, provide rebinding support. Especially rebinding controls from multiple controllers, because a lot of wheel/pedal/stick/throttle blocks plug in separately, and each appear as a separate "controller" to DirectX-et-al.


This is one thing in particular that's been lacking in, for example, Kerbal Space Program; when you mapped axes and buttons, you mapped Axis #N and Button #M across all controllers, so you couldn't use a stick for flight control and a throttle block for engines and systems control. At least, not unless you want "full power to engines" to also mean "hard a-port!"

#5313507 Looking for (mmo)rpg tutorial

Posted by on 01 October 2016 - 12:37 PM

There are no tutorials that will show you how to do something on that scale to any quality above "rubbish." You need to just start figuring it out on a piece by piece scale. Here's some of the important pieces you need re: networking...


Find a tutorial for simple (language of choice) client/server chat programs. That will get you started in the most basic, rubbish level of networking code.


Find the tutorials you need to make a level loader, complete with simple non-interactive NPCs (e.g. wandering non-hostile creatures or townsfolk) and loading triggers. Then make sure you can travel between dozens of such levels.


Then extend the latter to push your character id & level id & position to the server on a routine basis. Then extend it to receive NPC id & (create,update,delete) & position messages from the server, so the server can tell you when other players show up in, move around in, and leave the same level that you're in. Then make the server send updates sent by one player to all other players in the same room.


At that point, you'll have the most basic rudiments of a graphical MUD client.

#5302518 Create A Gaming Operating System

Posted by on 25 July 2016 - 12:49 PM

Ah, this old sausage. One of those questions where the very fact it is being asked ("How do I X?"), is itself an answer ("You are not yet ready to even start planning to do X."). You should maybe start with learning what Linux is and isn't; that is, where Linux ends and where the software you choose to install or develop for it begins.


For a practical experiment, I'd suggest installing minimal Ubuntu Server 32-bit (yes, the GUI-less one), and then following this AskUbuntu answer ( http://askubuntu.com/a/706073 ). When you run `apt-get install steam-launcher`, you will be presented with a list of all the software that goes into a window manager, an application stack, and a piece of user-space installation management software like Steam. To develop something like Steam, you will need to write or use nearly all of it.


Having experienced that brute-force education in the size and scope of what you are asking, instead of leaping into this multi-billion lines-of-code project you are asking us to show you "tutorials" for... you can instead tackle something a bit smaller. You don't need to write a Tetris game to develop an OS, but if you can't do the former yet, you definitely can't do the latter yet.

#5297128 Generating Provinces From A Map

Posted by on 18 June 2016 - 09:32 AM

Here's an algorithm that might do what you want.


1) "Seed." Iterate over your map in small chunks, e.g. 6x6 tile/pixel chunks. In each chunk, randomly pick a tile inside. If it is land, assign it a new, unique province ID.


2) "Grow." Once you've done that for the whole map, iterate across the entire map repeatedly. For each tile that does not have an assigned province but is adjacent to at least one province, have it adopt the province of a random cardinally-adjacent tile (or any adjacent if you're using hexes). Repeat this process until you walk the map and find no unassigned tiles that have at least one assigned neighbours.


3) "Sweep." Remove all land that has no province assignment at all. These are any islands which you didn't hit during the seed step.


4) "Inspect." Walk the map and get data for every province. You'll want to be able to take a province ID and look up its total area (how many assigned tiles), a location inside its borders (any will do; top-left, original seed location, whatever), and any other data you want to track about them at this stage. You'll also want to generate an adjacency map at this time.


5) "Prune." You'll probably have some provinces too small for your purposes, which won't be able to grow in the next step. For each province under a size threshold which also has zero neighbours, turn it into water and discard the province.


6) "Conquer." At this point, the average size of a province is going to be around the 6x6 area (remember the chunk size, in 1?). But you'll have lots of variety in size and shape everywhere. They will all have grown into irregular, blobby shapes. Now what you should do is start fusing these micro-provinces together! Start randomly picking provinces from the bottom 25% or so of them when ranked by size, and have it merge with a random neighbour. Overwrite the neighbour's tile assignments with its conqueror's, union the adjacency sets, and re-insert the new larger province in the rankings. The wider the conqueror selection is, the more variety in final province sizes you'll have at the end.

#5296550 Help with UV mapping procedural game

Posted by on 14 June 2016 - 07:42 PM

For exclusively plane-aligned faces, yeah it's overkill. I had domes and arbitrary 2D CSG polygons extruded upwards into buildings to cope with.

#5296513 Help with UV mapping procedural game

Posted by on 14 June 2016 - 11:55 AM

Although it's highly dependent on art style, I've used an object-space trimapping technique to avoid U/V mapping on my procedural terrain and CSG buildings. Each "material texture" is actually three textures, for the XZ, XY, and YZ planes. In the pixel shader, I use object-space position and a (uniform) scaling parameter to sample each of the three textures, then use the object-space surface normal to slerp between the three samples.


Con: no texture alignment; it's only suitable for tiled or detail textures on static objects.

Con: is relatively quite expensive when applied mostly to planar-aligned geometry.

Pro: works on any geometry; with good texture selection, it looks like natural, carved, or poured material.

Pro: no mapping or stretching artefacts.

#5294647 Isometric projection angles...

Posted by on 02 June 2016 - 09:05 AM

Right, but your viewing angle is not aligned with world axes. You need to recalculate the ball's "display" rotation based on its "physics" rotation. Assuming in your Spindizzy example that +X is down-right, +Y is up-right, and +Z is straight up, your camera is 60° around X and 45° around Z away from looking straight down (sign will vary based on left- or right-handedness of rotation). That Z rotation should be increased or decreased by 90° each time you rotate the camera.


For minimal change from your current codebase and process... each frame you should make a COPY of your ball's physics rotation, and apply a view rotation to that to match it up to your viewing angle, and then render using that apparent rotation instead of the ball's actual rotation.

#5294474 Isometric projection angles...

Posted by on 01 June 2016 - 09:01 AM

The projection from the basic view direction looks fine to me. Although I do notice in the Spindizzy example, you don't appear to be applying any friction against the ball spinning freely about the world vertical axis, which might be cause the appearance of wobble.


As for rotating the view... you're just rotating the ball around the view Z axis. You need to rotate the projection of the ball around the world vertical axis instead. You can tell this is what is happening by leaving the ball stationary with the number at the top. Rotating the view should leave the number at the top from all four directions, but instead you're rotating the ball as though looking straight down on it (where the view and world vertical axes are parallel).

#5292378 how can i use the CreateTimerQueueTimer()?

Posted by on 18 May 2016 - 05:28 PM

        ULONG flags;
        DWORD dwPeridic;
            flags = WT_EXECUTEDEFAULT;


Why not use the macro that actually exists, the way the documentation describes? The error you were getting is because the first parameter to the macro must be an assignable expression (an lvalue). Why do you need up to 500 threads to service your timer callbacks in the first place?


I have no idea what your (1) is asking.


As for your (2)... SetTimer() and KillTimer() deliver timer events as WM_EVENT events, and require a window handle. CreateTimerQueueTimer lets you specify arbitrary callback functions and callback parameters instead. AFAIK this design decision has nothing to do with the periodicity or precision of the timers associated with them.

#5292371 Introducing Stanza: A New Optionally-Typed General Purpose Programming Langua...

Posted by on 18 May 2016 - 05:11 PM

Trying to take prisoners in one of programming's holy wars is not user-friendly.


Maybe the language is useful. I can see some of the nicer features I got used to in Objective Caml hiding under the surface. Maybe the library is even robust and the compiler optimization fantastic.


But I don't have faith that any of these are true, after reading...



Indentation is important in Stanza programs. Be careful when trying out the examples.

And don't use tabs. Stanza won't let you. We don't like tabs.


Well, good for you. But this aggressive, inflammatory approach to user-friendliness just lost you an entire market of potential users who aren't even going to give the time of day to that attitude. It comes across as petty, and that's not something you want a reputation for. If you have a technical reason for blacklisting \t, put that in the documentation instead.




Also, a bug report: on 64-bit Ubuntu with 2 GB of RAM, after following the instructions to install Stanza and successfully running `stanza version`, I try to compile the "Hello World" example, and this causes `cc` to crash with an out-of-memory error while trying to consume a 7.6 MiB "tmp1.s" assembly.

[dispos@vbox: ~/mystanza]$ time ./stanza examples/helloworld.stanza -o helloworld
cc -std=c99 'tmp1.s' '/home/dispos/mystanza/runtime/driver.c' -o 'helloworld' -lm
Cannot allocate memory

real    0m38.292s
user    0m5.576s
sys     0m1.796s

[dispos@vbox: ~/mystanza]$ cc -v 2>&1 | tail -n 1
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)

[dispos@vbox: ~/mystanza]$ date -R --reference=../lstanza.zip
Wed, 18 May 2016 15:40:50 -0700

#5292358 how can i use the CreateTimerQueueTimer()?

Posted by on 18 May 2016 - 04:18 PM

Exactly as it says in the documentation: Due Time is how long until the timer first fires. Period is how long AFTER THAT it will fire again, and then again, and then again... unless it is zero. If you are getting a crash when you use a nonzero period, it sounds like something about your handler is crashing on the second or some subsequent timer firing.


If you expect the timer to fire once, and then never again, give a Period of zero. If you need it to fire multiple times over time, give it a period and debug your callback for what's really going on.



Also, on a resource waste note... you are creating a TimerQueue (a somewhat heavyweight object) for each of your timers, and then creating only one TimerQueueTimer (a lightweight object) in each of them.