Moving units
The whole reason I had to design and implement a new mouse engine was because the addition of units before was seriously conflicting with the old mouse engine. With this new mouse engine working perfectly in the RTS I was then free to change my focus back to the units. Before this big haste, I had units, and they were clickable, and even movable. Of course all of this fancy movement was a direct location change and not a fancy, slow, speed based movement, and all of the selection and move orders only worked at the origin view location. Basically, interacting with units didn’t work after scrolling and the movement was actually more like a teleport. However, all of that has been changed now.
When I started work on Saturday, I started focused on the main game loop which would control all unit incremental movement, and all other game updates. After spending some time getting that setup and integrated with the other engine, I then got distracted and started working on the selection engine. With the new mouse engine, I did need to rewrite some small pieces of the engine that did not convert directly over to the new system, but most of that was pretty minor and went very smoothly. After getting it back to the level of functionality that existed before, I then implemented new code to handle relative mouse clicks and move commands. The graphic part of the selection engine, before the action selecting occurs, is very simple in concept and implementation. The simple part of it went very quick except for a few typos I had to locate and fix along the way and the result was is very cool.
With the selection box in place I then started on a search algorithm that finds all units that have a center point within the newly created selection box. The search right now is, for the most part, completely un-optimized as the rest of the RTS, but I already have plans for optimizing both, the painting engine and the other generic searching algorithms to search less data to find exactly what they need. After getting the searching to work, I added actual selection to the units with the box, and even added modifiers for adding to the current selection and starting a new selection.Then, finally, after I was satisfied with the new selection box, I got back to making the units move. In no time at all I had implemented the skeleton of main game thread that linked it to each game object causing each to execute its current order, in the case if the units, move in the desired direction as the given speed.
Tags: Graphics Engine, Optimization, Scrolling, Units