• entries
  • comments
  • views

About this blog

Just a little information about some of the things that I have been working on.

Entries in this blog

[color=rgb(0,0,0)][font=arial]I've been away for some time now. A lot has changed since my last update. As I've said before, I used to teach English in Korea, but in April, my wife and I moved back to America. Now I've been trying to get back into the swing of things. I want to spend more time coding my game, and for a month, I did that, but since I need money for things like food and a place to live, I decided to get a job. Before I came back to America, I started doing some heavy networking and a 3D artist and designer that I've work with put my name into at this company M3D LLC which makes 3D printers. I've been working there for about 2 and a half weeks so far and like the startup environment. Everyone is very motivated and wants to put together a good product, but some the atmosphere is very relaxed. I guess that's what happens when you like what your doing. We joke around, talk, and do startup things like have barbecues. It's fun. It sometimes feels like a University of Maryland alumni meeting because almost everyone either graduated from UMCP (University of Maryland College Park) or is currently attending. I graduated from there in 2003. There's also an engineer who went to Yale. Yeah. He's pretty smart.[/font][/color]

[font=arial][color=rgb(0,0,0)]In my spare time, I still do Squared Programming stuff and continue to work on Auxnet. I've gotten a lot of work done on my AI system. For now I've decided to use a finite state machine as a low level framework of the AI system. I want to use the FSM system to develop more complex behavioral systems like planners, hierarchical FSMs, and behavior trees. The initial FSM system is done. Next I want to work on a navigation system that can be expanded to work with different algorithms and different kinds of maps. Then I'll add an extension to the system to allow state logic to be written in AngelScript. Once these things are done, I'll have a solid base. After that, I'll move onto other parts of the game like the animation and weapons systems. Once those are out of the way, I'll revisit the AI system.[/color][/font]


These days, I've been making a lot of progress on my AI engine. The basic framework is running now and you can see that in this video. The AI system is telling the little bot where to go. I'm still in the early stages of development so the path is still hard coded into the demo but I'm happy that I'm now at a place where I can concentrate on actual AI code more.

My goal going into to this was to build an AI system that would be useful for different types of games. As you can see in the video, the AI system is working on a simple 2D game. I also have a text based sample project and the main game that I am building this for will be a 3D multiplayer game. Internally, how does this all work? Games are so different that it's not easy to make a unified AI system so my goal was merely to provide the parts needed for AI that could be used in various game types and still allow the developer to build the AI by adding code directly to the system using C++ or by using scripting languages such as AngelScript or Lua. The AI system works like this:

Retrieve inputs from the game engine
- Entity health and location information
Process the current AI states
Send simple tasks to the game engine for each AI agent

The tasks that the AI system sends to the game engine should be very easy to complete. For example, if the AI system sends a "goto" command, the engine should be able to move to that location without worrying about obstacles. To navigate around obstacles, the AI system will send a series of "goto" commands marking points along the path.

Next Steps:
Currently everything is hard coded, but I want to provide a C++ interface so the AI programmer will be able to code custom behaviors. Then I want to expand that to include use a scripting language. After that, I'll start working on the navigation system. I'll continue to post information on my blog. For more videos, you can check out my YouTube channel. You can also visit ai.squaredprogramming.com.

I've been making a lot of progress these days. I've just finished most of a major renovation (hopefully the last until release) of the graphics engine. Before I had limited each model to one set of textures (diffuse, normal, effects map), but by artist request, I've added the ability to use a second set for added customizability(not a real word, but should be). I've also added the ability to change the colors of models in the engine. This will allow characters to be able to choose there colors. This isn't new earth-shattering technology, but it's a big deal for me.

I'll be moving back to the US tomorrow. Hopefully I'll be able to force my way back into the job market. I guess if things don't work out, I can always move back to Korea, but I'm going to try my hardest at becoming a successful indie developer.

Developing the AI Middleware's Interface

As I explained in my last post, I've developed a text-based sample game that I'll use to build the initial version of the AI system. Then I'll get it to work on my 2D engine, and then finally on my 3D engine for Auxnet:Battlegrounds. I'm at the stage now where I need to develop the AI systems public interface.

The AI system is still very early in its development so things will probably change, but this is how I invision using the code in a real application.

[code=js:0]// StartupRootAI::Engine *ai_engine = RootAI::CreateAIEngine();RootAI::WorldDesc worlddesc;...RootAI::World *world = ai_engine->CreateWorld(worlddesc);RootAI::AgentDesc aidesc;...RootAI::Agent *agent = world->CreateAgent(aidesc);...// Shutdownworld->DestroyAgent(agent);ai_engine->DestroyWorld(world);RootAI::DestroyEngine(ai_engine);

I haven't decided if I want to force the developer to have to explicitly destroy the agents and the world or allow just destroying the engine and have that take care of cleaning up everything. My current thoughts are to let the engine take care of cleaning things up and returning a message if there are any AI objects that weren't properly destroyed before the engine.

Here's the preliminary code for the AI agents and their tasks. The task should be basic enough so that the AI system can tell the game engine what in a way that will be easy to implement.

[code=:0]struct AIAgentDesc{ // the initial position and orientation of the entity Pose initial_pose; // set to true if the agent can move on more than one // axis at a time bool diagonal_movement;};enum AITaskType{ TaskIdle, // The AI should wait in an idle state TaskGoto, // The AI should go to a point (path will be unblocked) TaskAttack, // The an attack TaskTurnTo // turn to face a direction};struct AITask{ AITaskType type; union { struct { int animation_num; } IdleTaskOptions; struct { Vector location; } GotoTaskOptions; struct { int attack_number; Vector direction; } AttackTaskOptions; struct { Vector direction; } TurnToTaskOptions; };};class Agent{ public: virtual ~Agent() {} virtual void SetAgentPose(Pose pose) = 0; virtual void GetCurrentAITask(AITask &out) const = 0; virtual void SetTaskDone() = 0;};
The task currently just use unions. The reason why I decided to do it this way instead of using inheritance was I want to be able to easily copy data back and forth between the AI system and the game engine without creating new objects task objects and I can process the task without casting.

Another design choice that I've made is completely separating the public interface from the implementation. That's why the agent class is an abstract base class. The same will be true of the world and engine classes.

Let me know if you have any questions or suggestions.

AI video for beginners and young programmers

Squared Game Engine Modular Architecture

Fun Indie Games In Development YouTube Playlist

[color=rgb(0,0,0)][font='Times New Roman'][size=1]

AI - Progress


[color=rgb(0,0,0)][font='Times New Roman']Things have been going well on the AI front. I'm still hoping to have a strong enough foundation in a few weeks to be able to put my source code up on GitHub. It'll still be very early in the process, but I think I should have more than just a skeleton before I allow others to see the code.[/font][/color]

[color=rgb(0,0,0)][font='Times New Roman']I've been looking at various middleware SDKs, namely RakNet, NVidia PhysX, and AngelScript, just to get a feel of what makes a good SDK. I've decided for now to go the RakNet and AngelScript route and have all of my samples be console applications and not graphics applications. I still will make a 2D version of the sample, but it won't be an official part of the Root AI SDK.[/font][/color]

[color=rgb(0,0,0)][font='Times New Roman']Here's a screenshot of the console based example game. The AI system isn't being used yet so the AI bot just uses simple code to move left. Soon it will still just move left, but it'll be the AI engine telling it to do so.[/font][/color]

[color=rgb(0,0,0)][font='Times New Roman'][size=1]AI+Screen+shot.png[/font][/color]

[color=rgb(0,0,0)][font='Times New Roman'][size=1]

Auxnet: Battlegrounds - Update


[color=rgb(0,0,0)][font='Times New Roman']As for the game Auxnet: Battlegrounds, I just received the base animations from our 3D modeller so now I have the needed test data to start working on enhancing the animation system. I want to get a video of the new animation up soon.[/font][/color]

[color=rgb(0,0,0)][font='Times New Roman']articles.squaredprogramming.com[/font][/color]

[color=rgb(0,0,0)][font='Times New Roman']ai.squaredprogramming.com[/font][/color]

These days, I've been turning my attention towards AI. In the past, I spent so much time working on graphics components of the engine in the past, that I've never put the effort into building a good AI system. When I was developing Genesis SEED, I wrote a complex AI system, but it was too unwieldy and complicated so I decided to start from scratch when working on the AI system that would go into Auxnet. It's still in its beginning stages but in the long term, I'd like to release the AI system as an open source project. I want to build a general AI framework that will work on many different game types.



How and why do I want to make a general AI framework? I want to build this game engine in a modular way to allow for future expansion. To achieve this modular approach, the code will naturally take a framework with attached plug-ins design. I know that AI is very game specific, but what I want to do is provide a collection of techniques that the AI agents can have to complete their task. After that, the main architectural design issues will come down to how to separation of responsibilities between the AI engine and the game engine. I'm not an AI expert, but I have experience in designing architectures and feel that I'll be able to put together a good system.



The AI system will have three main parts, the engine, worlds, and agents. The engine holds the worlds and is responsible for initialization and the destruction the system. Multithreading support will also be handled in the engine. Worlds contain agents and also the navigation system and world geometry. Keeping separate worlds will an application to use one AI engine to process the AI for agents in unrelated and unconnected areas. Agents are the actual AI entities and are connected to an entity in the game engine. There is no direct link between game engine entities and AI system agents in code so the agents will need to store copies of some of the the game engine entity's data such as position and health information. I've given a very simple UML diagram below with some of my current thoughts. This will grow by leaps and bounds by the time end of the project.





I want to model my AI system like other middleware SDKs. I've used many different kinds of middleware including, graphics APIs, physics SDKs, networking engines, and scripting languages. Of all of the different middleware libraries that I've used, which system is most like the AI engine that I want to build? Believe it or not, this system will be most similar to a physics engine. Think about it, in a physics engine, first, you should set up the world or scene, then add actors and physics bodies. After that you run the simulation, checking to see the new position and orientation of your actors and then updating them in the engine. An AI engine in many ways is quite similar. First you have to setup the world and tell the AI engine how the level is laid out and what potential colliders and dangers are in the world. Then you should create AI agents that are connected to game entities to populate the world. The AI engine will run the simulation, and then the entities in the game engine should check their AI components to see what state changes have been made. That's the entire system in a nutshell.




For this to work, I'll need a very simple interface. The AI engine will be responsible for all decisions. It will tell the game entity to do simple task like move forward, turn, or shoot, and then game engine should do task and tell that AI engine when it has completed the task. The task that the AI engine will relay to the game engine should be simple enough to not need any complex intermediary AI. For example, if the AI engine returns a "go to" command, the entity should be able to go to that point by walking in a straight line and without worrying about path finding. For complex paths, the AI engine should give a series of "go to" commands until that agent has reached its destination. In this way, the AI engine will be the brains and the game engine will act like the nervous system and make the agent's body move. So the game engine to receive instructions from the AI engine, and for the AI engine to receive position information and whether or not the instruction has been completed. This information will not need to be sent back and forth every frame, but either as needed or at set regular intervals as decided by the developer. Game engines that used a component-based entity system can add an AI component to process instructions from the AI engine and to pass on the entity's location information to the AI engine. The game engine should also be able to send events to the AI engine that are not directly tied to a specific entity such as level events, so the AI agents will be able to respond to those events as well.



There's no way I'll be able to program all types of AI algorithms so the AI engine will need to not only be flexible but expandable. I'll have to build it so it can take add-ons written in either C++ or in scripting languages such as AngelScript and Lua. The add-on system should not be limited to giving support for different types of levels and path finding. There should be a way to make add-ons that will affect how decisions are made so there should be add-ons for using Ad-hoc rules, finite state machines, behavior trees, neural networks, and so on. Once a large library of add-ons has been created, building complex AIs will be a matter of choosing the proper base AI architecture (Ad-hoc rules, finite state machines, etc), adding skills, and performing some game specific tweaking. These are my AI goals.



To help me build all of this, I've created a small 2D game with a little robot that should navigate through a simple maze. I'll develop this demo more and more and post updates on my blog and on YouTube.






This has been reposted from

Auxnet development has been picking up these days. Right now my main task is AI. AI has been a pain in my side for some time now not because I don't know how to do it, but because I haven't really had a lot of time to work on it. So I've been stuck in stupid AI land. I'm going to change that now. I'm determined to make AI agents that don't repeatedly bump into walls. I've been putting together a nice little AI framework. If all goes well, I'll try to give regular updates on my progress and even some code. I did some research on many AI topics and made this little video as a little summary.

It took a long time to make this and it's either programmer art at its finest or at its worst. Who would have thought making bad animations would be so complicated? I hope the animation is entertaining and informative--well as entertaining as AI can be. The order of the topics is from an article that IADave wrote but all of the explanation is from my own head. I give brief info on using simple rules, finite state machines, behavior trees, planners, and neural networks. I some had serious flashbacks from my college AI class. Sadly that was the most boring class I took during that four and a half year period.

For a more complete synopsis of what I plan to build, you can check out journal.squaredprogramming.com .

[font=arial][color=rgb(0,0,0)]Graphics-wise, I don't plan on changing my current 3D engine much. I've mostly been working on gameplay and AI related stuff. As I make more progress on the AI code, I'll share it here and on my main page. Currently the 3D engine, Squared'D, has too many parts to use it as a simple testing platform so I stripped out it's core 2D elements (these were mainly used for the GUI) and built it into a smaller game engine that doesn't require much set up. I'm using the 2D engine for experimentation with new concepts.[/color]

[color=rgb(0,0,0)]I've been trying to leverage more C++ features to make development easier. One big design decision was to limit the use of pointers and to use handles and C++ references as much as possible. I want to avoid using shared pointers and limit my code to only a few unique pointers when absolutely necessary. So far so good. I've gotten a component-based entity system working already. Entities only store handles to there components, and all components are stored in an std::vector inside their respective system classes. As I've been playing around with the system though, I think in the future, entities will not even need handles to their components. Entities will eventually just morph into position orientation with the components knowing which entity they belong to, but not the other way around. If it goes well, I'll incorporate these ideas into the next version of the 3D engine. Hopefully I'll be able to simplify things enough so that the next 3D engine will be good for testing and able to run on the PC and Android, but all this will happen after 6 months or so.[/color]

[color=rgb(0,0,0)]If you'd like some more details about the 3D engine's modular design, you can check out the video below. Let me know if you have any questions. Even critiques are welcome.[/color][/font]


The Latest

I've been living in Korea for the past 6 1/2 years, but my wife and I have decided to give the US a try and we'll move back there this spring. So I'm now in job hunting mode. I've also been taking some time to develop my personal website www.squaredprogramming.com . I've been posting a lot of things there. I've added the articles that I've published here on Gamedev.net as well as some new ones. On my journal page, I've posted the article, "Indies--Stop Treating Your Ideas Like Classified Secrets" (http://journal.squaredprogramming.com/2014/02/secrets.html) which goes over why I think indies should be open about sharing there ideas.

I've been studying a lot, trying to prepare myself to reenter the US work force. I'll move back to Maryland at least in the beginning. I'll see how it goes.

If you have time, check out my new site. Good suggestions and comments are always appreciated.

This has been re-posted to http://articles.squaredprogramming.com/2014/02/smartpointers.html


This is a journal entry not an article so I feel like I can ramble a bit before I get to the main point. I have been programming for some time now and got my CS degree way back in 2003, but in 2007, I decided to take a break from programming, moved to South Korea, and have been an English teach ever since. I started to program again and with the help of an artist friend of mine, made this for last year's IGF. We obviously didn't win and haven't decided whether or not to continue with the project.

Anyway, because of my long hiatus from programming, quite a few things have passed me by, namely modern C++ and all of this smart pointer stuff. I've decided to start writing code not just for myself, but code that others could use so I want to update my knowledge of C++ and explore smart pointers. In this journal entry I want to share what I've learned. I don't claim to be an expert, so if you have any useful insights or corrections, I'd appreciate a "friendly" comment.

Raw Pointer Primer

There are two basic ways to create a variable in C++: stack variables and heap allocations. Stack variables are defined inside a certain scope and as long as you're in that scope, the variable will exist. Heap allocations (dynamically allocated memory), variables typically declared with new or malloc, aren't not defined within a scope and will exist until the memory is freed.

Here's an example:void foo(){ // Object A of class CSomeClass has been declared inside the scope of foo CSomeClass A; // do some stuff .... // you can even call other functions and use A as a parameter Func1(A); // This could be pass by value or pass by reference depending on Func1's declaration Func2(&A); // Passes a pointer to A // at the end of this function, the scope will end and A will automatically be destroyed}
Now with this function, every time another function calls foo, A will be created and then destroyed when the function exits. Not bad right. What about this?void foo(){ // Object A of class CSomeClass has been declared inside the scope of foo CSomeClass *A = new CSomeClass; // do some stuff .... // you can even call other functions and use A as a parameter Func1(*A); // This could be pass by value or pass by reference depending on Func1's declaration Func2(A); // Passes pointer A of CSomeClass (Edited) // MEMORY LEAK // at the end of this function, the scope will end, but A was created on the heap // delete should be called here}
So with dynamic memory allocations, you must free the memory. So why you might ask do we even need dynamic memory allocations? Well one, to declare variables on the stack, you need to know exactly what you'll need at compile time. If you want to be able to create arrays of various sizes depending on user input, or if you're making a game and want to load variable amount of resources, you'll need to use dynamic memory allocations. Take this example:int num_students;// First get the number of students in the classstd::cout << "How many students are in the class?"std::cin >> num_students;// Create a dynamic students arrayCStudent *student_array = new CStudent[num_students];// Do some stuff with the data....// call the array version of delete to free memorydelete [] student_array;

In the previous situation, you must use dynamic memory because the size of the array is determined by the user. How can smart pointers help?

Smart Pointers

(chief reference: Smart Pointers (Modern C++) on MSDN)

Smart pointers allow you to create dynamic memory allocations but defined them inside a scope or an owner. This way, when the owner goes out of focus, the data will be automatically deleted. Smart pointers have been implemented using templates and to use them, you must include the header . Smart pointers are in the std namespace. I will only discuss unique_ptr's here. Later, I may talk about the other types of smart pointers in between updates to "A Complete Graphicsless Game"

So how do you create a unique_ptr?
std::unique_ptr apples(new Base(L"apples")); // Where Base is the class type
You create a unique_ptr like a typical template and then pass the raw pointer to initialize the variable. After that, you can use the unique_ptr, just as you would any other pointer.class Base{ public: Base(const std::wstring &string) :m_string(string) { } virtual void Display() const { std::wcout << L"Base:" << m_string << std::endl; } private: std::wstring m_string;};int main(){ // declare some unique_ptrs. This pointers can have only one owner and cannot be copied. Only moved. std::unique_ptr apples(new Base(L"apples")); apples->Display();}
unique_ptr's can also be passed to other functions, but you must pass by reference. Passing by value will result in a compiler error. With unique_ptr's, only one can own the pointer, but if you pass by value you will make a copy of the unique_ptr which in essence makes two unique_ptr's that own the same block of memory.

You can also use unique_ptr's with derived class and virtual functions and get the typical C++ behavior.class Base{ public: Base(const std::wstring &string) :m_string(string) { } virtual void Display() const { std::wcout << L"Base:" << m_string << std::endl; } private: std::wstring m_string;};class Derived : public Base{ public: Derived(const std::wstring &string) :Base(string) { } virtual void Display() const { std::wcout << L"Derived:::"; __super::Display(); // __super is MS specific. Others should use Base::Display(); }};int main(){ // declare some unique_ptrs. This pointers can have only one owner and cannot be copied. Only moved. std::unique_ptr apples(new Base(L"apples")); std::unique_ptr oranges(new Derived(L"oranges")); apples->Display(); oranges->Display();}
This is very useful when dealing with vectors as the next example show.std::vector > test_vector;test_vector.push_back(std::unique_ptr(new Base(L"apples")));test_vector.push_back(std::unique_ptr(new Derived(L"oranges")));
In the above example, you can use the vector of unique_ptr's in the same way you would if it was a vector of raw Base pointers, but there is one nice benefit. If this vector had raw pointers, you'd have to make sure you manual free the pointers before you clear the vector or erase an element, but with unique_ptr's, all of that is handled for you.


I hope this information was helpful. I am in no way an expert so if you anyone sees something glaring that I missed, feel free to leave a "kind" comment. If you would like to know more about smart pointers, I suggest checking out the like on msdn.
It's been a while since I've written a blog post. I had been spending a lot of time learning and exploring AngelScript. I won't be writing anymore AngelScript articles for Gamedev.net, but from time to time, I'll post blog entries on it.

These days, because of personal reasons of the other team members, Auxnet progress has slowed down a lot, but I hope to get back to it soon. While I wait for everyone to catch up, I've been experimenting with some new engine concepts. I've decided to build a little test engine currently code-named "Engine X" to try out the concepts. It'll be a multiplatform (Windows / Android) 2D tile-based engine that will use AngelScript as the scripting language. I'm not sure how much time I'll be able to devote to it though because it'll go on the back burner once things with Auxnet ramp up again.

I've got the base rendering and user input stuff working on Windows. Later I'll build it for Android. In the meantime, I've been working on adding support for a tile layer. I don't have time to make an editor so I'm going to use Tiled which can be found at mapeditor.org . I want to build a simple loader for it. The format is in XML so it's not overly complicated, but there was one thing that's new to me.

The tile data is stored in Base64. At first, I didn't know what this was so I decided to do a little research. Base64 is an encoding that takes data whether binary or text and encodes it using only 64 characters. This is useful when transmitting data over protocols that may alter the data. As it turns out, the pioneers of the Internet and email weren't forward thinking enough to think that more than 7-bits (thank you ASCII) would be needed for transmitting a text character. Base64 can also be used to store complex data inside things like XML. There are different forms of Base64, but they all work on the same general principle, It's used as a way to store binary data as plain text. It's not a complicated encoding. Basically you take three 8-bit bytes and break into four 6-bit units. The 6-bit units will be from 0-63. To make sure the values will be able to be transmitted without being garbled, the final character for each value is determined by the following table.


The above table is for Multipurpose Internet Mail Extensions (MIME). Other versions of Base64 use a similar table, but in some of them the characters used for values 62 and 63 are different. The above characters are good because they are supported by the majority of text encodings and aren't the same as any XML or HTML tags. For binary data to be converted into base64, the number of bytes should be a multiple of three. If not, it should be padded with zeros. When this padding occurs, and special 65th character, '=', is used instead instead of the normal 0, 'A' character. This means '=' will only appear at the end if there was padding.

Here's an example:


Now, I'll continue working on loading the map. Hope to have a working tiled-based rendering system within the next 7 days.

This entry was originally posted on the Squared Programming Blog: http://squaredprogramming.blogspot.com/2014/01/i-had-been-spending-lot-of-time.html
This is a re-post from my blogspot entry: http://squaredprogramming.blogspot.com/2014/01/c-stl-style-array-thats-compatible-with.html

C++ STL-Style Array That's Compatible with AngelScript

I guess this will be like part 1.5 of my 2 part article on AngelScript. I've been working on a new class that I think will be useful to programmers working with AngelScript. AngelScript is nice because its data types are so similar to C++ that it's easy to bind it and share data. There's one thing that doesn't have an easy one-to-one AngelScript counterpart and that's static arrays. I can understand the reasoning behind this as the script has no mechanism that it can use to garuntee the life time of the array. AngelScript does have a nice add-on for arrays that's generic and can add arrays for any type, but I wanted something easier. I decided to make a template class that would wrap the CScriptArray add-on and give it an interface like std::vector including stl-style iterators.


Using the class.

The CScriptArraySTL class was designed so that the array can be created in C++ and then shared with AngelScript as a registered property, or as the return value of a registered functon. It is a template class that takes two template parameters.

[code=:0]template class CScriptArraySTL
The first parameter is the type, and the second parameter is the internal array class that has been registered with AngelScript. The default array class is the CScriptArray add-on that is included in the AngelScript SDK. To use this it, you must also include the CScriptArray add-on in your project and register it with AngelScript using the RegisterScriptArray() function. The internal array class is given as a template argument to allow the programmer to be able to use there own array implementation.

Declaring a variable:
[code=:0]// uses CScriptArray addon internally// for this to work, std::string should be registered with AngelScript.// This can be done using the ScriptStdString add-on.CScriptArraySTL string_array; // uses a user-defined array type called CScriptArrayInt// this type should be a specialized version of CScriptArray that only handles integersCScriptArraySTL int_array;
You can create variables using CScriptArraySTL anytime, but you can't use it until after the CScriptArraySTL object has been initialized using
the InitArray() method. Here's the declaration for that function:

[code=:0]// Initializes the array so it can be directly accessed using AngelScript// This must be called before the array can be usedint InitArray(asIScriptEngine *engine, char *declaration, size_type init_length = 0);
asIScriptEngine *engine
The first parameter is a pointer to the script engine. To maximize compatibility with AngelScript, this class uses creates it's internal data using the types that have been registered with AngelScript.

char *declaration
The second parameter is how you would write the type for this array in AngelScript. This allows the class to match its type with AngelScript. For example, if the class holds integers, it should be written "array".

size_t init_length
This is the initial size of the array.

This function returns a pointer to the internal array class and can be registered with AngelScript as a property or returned from a function that has been registered with AngelScript.

This will release a reference to the array. After this method has been called, the CScriptArraySTL class will no longer be able to access the array data; however, as arrays are reference types in AngelScript, the data may still exist inside AngelScript until the reference count is zero. This method should be called before the script engine is released.

Sample Code

[code=:0]// Create the script engineasIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); // Register needed add-onsRegisterStdString(engine);RegisterScriptArray(engine, true); // setup our string arrayCScriptArraySTL string_array;string_array.InitArray(engine, "array"); // register our array as a global variable in the scriptr = engine->RegisterGlobalProperty("array string_array", string_array.GetRef()); assert( r >= 0 ); // do other things and load and run scripts... // Release the arraystring_array.Release(); // Release the script engineengine->Release();

[color=#ff0000]Get the Source.[/color]

The source code and a example project can be found on GitHub. If you copy the "scriptarraystl" folder to the AngelScript SDK add_on folder, the project directory paths should work. Only a Visual Studio 2010 solution is being provided, but you should be able to run it using other compilers. To use this class in your project, all you need to do is include "ScriptArraySTL.h" The class has been implemented entirely in one header file.

GitHub link: https://github.com/squaredprogramming/scriptarraystl


Here's the complete list of the methods that I've implemented for the class.

[code=:0]// Constructors, Destructors and AngelScript initialization -------------------------------CScriptArraySTL(void);~CScriptArraySTL(void); // Initializes the array so it can be directly accessed using AngelScript// This must be called before the array can be usedint InitArray(asIScriptEngine *engine, char *declaration, size_type init_length = 0); // returns a pointer to an array class that can be used in an AS scriptTArrayClass *GetRef(); // Releases a reference to the array. After this is called, this class can// no longer access the array data, but the data may still exist inside// AngelScript until the refernce count is 0.void Release(); // Capacity ---------------------------------------------------------------------------------- // returns the number of elements in the arraysize_type size() const; // resizes the array, adding unitialized data if the new size is bigger than the old size or// deleting data if the new size is smallervoid resize(size_type n); // returns true if the array is emptybool empty() const; // grows the buffer capacityvoid reserve(size_type n); // iterators ----------------------------------------------------------------------------// returns an iterator to the begining of the arrayiterator begin(); // returns an iterator to the end of the arrayiterator end(); // returns a constant iterator to the begining of the arrayconst_iterator cbegin() const; // returns a constant iterator to the end of the arrayconst_iterator cend() const; // returns a constant iterator to the begining of the arrayiterator begin() const; // returns a constant iterator to the end of the arrayiterator end() const; // returns a reverse iterator to the begining of the arrayreverse_iterator rbegin(); // returns a reverse iterator to the end of the arrayreverse_iterator rend(); // returns a constant reverse iterator to the begining of the arrayconst_reverse_iterator crbegin() const; // returns a constant reverse iterator to the end of the arrayconst_reverse_iterator crend() const; // returns a constant reverse iterator to the begining of the arrayconst_reverse_iterator rbegin() const; // returns a constant reverse iterator to the end of the arrayconst_reverse_iterator rend() const; // Element Access ----------------------------------------------------------------------- // returns a reference to an element in the array. This will not throw an out-of-range exception.// undefined behavior if out of range.reference operator[](size_type index); // returns a const reference to an element in the array. This will not throw an out-of-range exception.// undefined behavior if out of range.const_reference operator[](size_type index) const; // returns a reference to an element in the array. This will throw an out-of-range exception.reference at(size_type index); // returns a constant reference to an element in the array. This will throw an out-of-range exception.const_reference at(size_type) const; // returns a reference to the first element// undefined if emptyreference front(); // returns a constant reference to the first element// undefined if emptyconst_reference front() const; // returns a reference to the last element// undefined if emptyreference back(); // returns a constant reference to the last element// undefined if emptyconst_reference back() const; // Modifiers ------------------------------------------------------------------------------------ // adds a value to the end of the arrayvoid push_back (const value_type& val); // removes the last elementvoid pop_back(); // assigns new data to the array using iterators.template void assign (InputIterator first, InputIterator last); // fills the array void assign (size_type n, const value_type& val); // clears the contents of the arrayvoid clear()

Preview my new article

I've been working on a new article that I hope to post here on Gamedev. It's currently already up on my other blog. It'll be a two part article so I want to finish them both before I post them here. You can take a look at it here: http://squaredprogramming.blogspot.kr/2013/12/programming-by-example-adding.html

The basic premise of the article is showing how to add AngelScript to a game, by taking an already made game, in this case the XACT Game sample from the Direct X SDK, and scripting parts of it.
I've been doing a lot of things these days. After spending the past few years as a shut in hermit programmer, I've been trying to spread out and become more public. I've been teaching English for the past 6 years, but I'm hoping to get back into programming. I think increasing my reputation on the internet will help me in that endeavor so I've been trying to as active as possible and getting in touch with various online communities.

Write now, I'm starting to look at adding scripting to my game. I'm working on an experimental side engine to test things on apart from my main game. I've just downloaded the latest version of Angel Script to my computer. I want to see if I can use that to separate game specific code. I've been thinking about porting my experimental side engine over to Android. I think using a scripting language will allow me to further distance the game specific code from platform specific work.

What I've been working on:

STL-Style UTF-8 String Class now on GitHub - http://squaredprogramming.blogspot.kr/2013/12/utf8stringonGithub.html

Squared'D YouTube Channel - https://www.youtube.com/channel/UC-QAiqVnw6nVrFzW__fZeeA


Using UTF-8 in Games


Using UTF-8 in Games



After working on my GUI system, I really started to explore using UTF-8 more in my game. I'm currently living in Korea and that has made me see how important it is to give people games in their language. The kids I teach are just crazy about video games. The game Starcraft, for example, was at one time so popular in Korea, it spawned sponsored professional game players. Matches can be even seen on game-specific cable television networks. There is a large international desire for games and developers should build their games with this in mind.



I've started looking at UTF-8 these days and trying to explore it. I've written an article on it and I've even made a video presentation based on that article. And if you like want source code, on my other blog, I'm currently writing a series Writing a STL-Style UTF-8 String Class. It will be a five part series that I should finish by Friday. If it gets a nice reception, I'll post a summary article here on Gamedev. Even with all of this information, plus the countless articles on the Internet, how can someone actually use UTF-8 in a game?



UTF-8 is a Unicode encoding. One good thing about UTF-8 is it's a variable-sized 8 bit encoding. This means that games developed using 7 bit ASCII(the 8 bit "char" data type in C and C++) will not need to alter their file formats that store text. This is because 7-bit ASCII is a subset of UTF-8 and UTF-8 can work with null-terminated c-style strings. All of the standard "char"-based string functions will work including search, concatenation, and comparison.


To use UTF-8 with a GUI, the text can be stored in UTF-8 and then converted during rendering. This can be done by iterating through the string to get the correct code point. For GUIs that render text that doesn't need further processing, this will work well. Edit boxes will be a little trickier since they will require random insertions of characters anywhere in the text field. This can be done using a good UTF-8 string class, but it would be better to not use UTF-8 in this case and convert later. This makes sense as an edit control will probably have it's own buffer for text anyway that will later be synchronized with the application.



Another thing UTF-8 is good for is sending data. Even when a game already uses wchar_t(16 bits on Windows), UTF-8 may still be used when communicating with other programs over a network. Many network libraries and many servers require request to be sent in JSON or XML encoded in UTF-8 so even if the program stores it's text internally as wchar_t, conversion to UTF-8 may still be needed. UTF-8 is good for sending data because it is endian-independent. One example of this is the RakNet master server implementation by Jenkins Software. To use it, applications should send data in JSON over HTTP. User names, chat messages, and room details can all be encoded in UTF-8.



I'll continue to post about my progress and as I get more information I'll also post it here.


[font=arial]Adding Attachment Models to Entities[/font]

[font=arial]I've successfully added model attachments back into my 3D engine. I'm providing a video entry that gives some details about how I implemented it. Because all 3D engines are different, I only give show shader code, but I think the explanations are nice and clear. This is probably one of my most informative videos. If it gets a nice reception, maybe I'll make more. I really put a lot of effort in to this video. It's taken me a few days to complete. I actually wrote a script for it and planned how I'd put it together. Enjoy.

If you'd like information on creating a skeletal animation system, here are some links. In the Direct X SDK, there is a sample on this topic as well.[/font]

Here's a basic bone system that uses Open GL, but the concepts be used with Direct X[/font]

A wiki that explains what skeletal animation is.[/font]

An old discussion on Gamedev.net about implementing a bone animation system.[/font]

A basic Skeletal Animation Tutorial[/font]

[font=arial]Feel free to check out my Google plus page for updates and check out my YouTube channel.[/font]

[color=rgb(40,40,40)][font=arial]Google+: [/font][/color]Squared'D Game Google+ Page
[color=rgb(40,40,40)][font=arial]YouTube: [/font][/color]Squared'D Youtube Channel

Middleware and 3rd Party Libraries in Auxnet - Part 2 - Phys X


It's been a couple of weeks since I've updated, but I want to continue writing about the different middleware and 3rd party libraries that I've been using. Now I'll give some information on how I use the popular physics library PhysX by Nvidia.

What is it?

PhysX is the physics library from Nvidia. It was made by Nvidia, but it works on non-Nvidia graphics cards. I use version 3 which doesn't require any additional drivers to be installed.

PhysX can be used for rigid body physics and collision detection. It has built in shapes that can be used such as boxes, spheres, and capsules. It also supports heightfields, convex hulls, and triangle meshes.

Why did I choose it?

I was in need of a nice collision detection system and this suited my needs nicely. At the time that I found out about this, I was just a hobbyist and was looking for a free solution (or at least something that would be free until I started to make money). I tried two other physics engines and felt the most comfortable with this one.

I also liked the Phys X 2 documentation. The documentation for version 2 is much more complete than PhysX 3, but after becoming familiar with 2.8, version 3 was not too difficult. If you don't have much experience, working with the Phys X 3 documentation may be a little difficult. Even I often have to study the example code to try to figure out what's going on sometimes.

How do I use it in the game / engine?

I currently only use PhysX for collision detection. My game engine has one major division in its objects based on class lifetimes. The first division is application level and the other is state level. Application level objects are classes that need to be alive from application start until the application dies, and state level objects live and die with a state. I also use a plugin system to add functionality that's similar to adding components in a component-based entity system. Because of this, I have two basic classes that I feel fit nicely with the way PhysX is organized, CPhysX3AppAddon and CPhysX3StateAddon.

This class is responsible for physics objects whose lifetimes are the same as the app and things that shouldn't be created and recreated. It includes the following:[code=js:0]physx::PxFoundation *m_Foundation;// This should be created first to instance the higher level SDKs. As stated in the// docs "Every PhysX module requires a PxFoundation instance to be available"physx::PxPhysics *m_Physics;// This is a factory class used for instancing objects in the Physics SDK.physx::PxCooking *m_Cooking; // Only if needed// This is used to preprocesses or cook raw data and turn it into a form that can be used by PhysX
The main job of this class is to take care of the scene. So it keeps an instance to a physx::PxScene *m_Scene object. All physics bodies should be associated with a scene. As stated in the docs, "a scene is a collection of bodies, particle systems and constraints which can interact. The scene simulates the behavior of these objects over time. Several scenes may exist at the same time, but each body, particle system or constraint is specific to a scene -- they may not be shared."

The engine uses component based entities. Physics components are registered with this class.

What are my future plans?

I hope to be able to do more things with PhysX in the future like being able to throw things and have them bounce in a realistic way. I also want to see what interesting effects I can achieve by adding things like forces and adjusting gravity. Code-wise, when it comes to the ever evolving design of this engine, I want to see if CPhysX3AppAddon is even necessary. Maybe it would be better to keep things together and create and destroy all Phys X objects with the state.

Squared'D on social media

These days, I've been trying to increase my internet presence. I'm on Google+ now, and I have a YouTube channel. If you'd also like to gain more exposure, let's subscribe and follow one another so we can pick up more followers. I think this could help some of us grow our brands. You can leave a comment below if you think this sounds like a good idea. I'll follow most games; however, I'm not into over the top violent and horror games.

Google+: Squared'D Game Google+ Page

YouTube: Squared'D Youtube Channel



Middleware and 3rd Party Libraries in Auxnet - Part 1 - Direct X

Making a game like Auxnet has been a very daunting and tiring task. I work on a team; however, I'm the only programmer. Making such a game alone wouldn't be possible unless I used various libraries and APIs. I guess it would be possible, but it would have tripled the amount of time spent. In this series of blog post, I'll examine some of the middleware that I used to create the game. I'll examine them by considering the following questions:

  • What is it?
  • How do I use it in the game / engine?
  • Why did I choose it?
  • What are my future plans?

    I hope this will help anyone who is thinking about including middleware in their projects.

    Direct X

    What is it?
    Quick disclaimer. In this post, when I say Direct X, I'm actually just refering to Direct 3D. Direct X is the Windows graphics API that I decided to use. Direct X provides an interface that allows me to use the various features of the graphics card. Using HLSL(High-Level Shader Language), it's possible to write per vertex and per pixel programs to create many interesting effects.

    Why did I choose it?
    I have intention of starting a Direct X / Open GL debate. I've honestly never used Open GL. I decided on Direct X because it was created by Microsoft, and the only platform that I currently support is Windows and with MSDN and all of the Direct X samples included with the Direct X SDK, it was easy to start with. At first, I only supported Direct X 9, but now the game/engine also supports Direct X 11. I've developed a multiplatform framework that I hope will allow me to expand to other operating systems and using Open GL in the future, but for now, I just want to finish the game so I'm sticking with Direct X until the game has been completed.

    How do I use it in the game / engine?
    I use Direct X for all of my rendering. I've written two frameworks that sit on top of Direct X. One is very high level and uses handles to refer to resources. The other is much closer to the API. This has been working well, but as I've been coding, I've been realizing the benefits of the higher level framework and am considering phasing out the lower-level API-like framework and just and work on making the higher-level version faster. The higher-level framework is built on top of the lower-level stuff so I feel like I'll be able to eliminate a lot of code the and make it faster by just have the higher-level framework directly access the API. I'll continue to experiment with this and make a final decision after this game has been completed. No more major engine changes unless they are 100 percent needed to complete the project.

    I make extensive use of HLSL shaders and created my own material system that uses different shader techniques and texture maps to make various effects. Most surfaces use 3 textures--diffuse, normal, effects. The effects texture contains extra per-pixel information for things such as glow and specular. Models are rendered in order based on their shader and texture combination to reduce changing the texture. Translucent things are rendered in a second past using a z-sorted order.

    What are my future plans?
    There are quite a few graphical features that I'd love to add. I've been doing a lot of reading on deferred rendering systems and feel that I'd be able to get a lot of interesting lighting effects with it, but shadows are what's actually high on my todo list. I'd also like to add more support for other kinds of visual effects like electricity, smoke, and other particle effects.


    To follow the project here on Gamedev, you can visit here https://www.gamedev.net/page/indie/project.html/_/action/auxnet-battlegrounds-r18
    You can also follow the project on Youtube here: http://www.youtube.com/channel/UC-QAiqVnw6nVrFzW__fZeeA

    Google+ Gallery: https://plus.google.com/112888538773179540556/posts/DAQhfYqUMyH

An Experiment in Creative Writing

As I think I've said before on this blog, I program games and I want to do it full-time, but as of now, my day job is teaching English as a foreign language in South Korea. I live in a small town called Anseong, which is about 1 hour south of Seoul, the capital city. Education here is very test-centric with a lot of emphasis placed on just memorizing things. I've been trying to get my students out of this by having them make random sentences about random things and not just diaries about their lives. Sometimes I also like to give my classes a sentence which is the beginning of a story. Then I have the students add a sentence to the story one at a time. I did this in one of my classes and I was so impressed by their ideas, that I gave the same premise to four other classes. Their final stories were very different. I'll post my favorite four here. The fifth one was a little to silly. It's interesting how some students want to continue the story and some others try to add things that will make it go in a completely different direction. I teach at a hakwon. Hakwons are small schools that students come to after their regular school to learn about a certain subject so my classes are small.

#4 (8th graders)
It is the year 2113, and Anseong, Korea is a big city, but it has a problem. It rains in Anseong everyday, so there is a big flood in Anseong. The people in Anseong always bring umbrellas. Many people have died because of the flood. Also, many flowers don't grow. The stores are underwater, so the people aren't able to buy food. One day, the rain stops. Many people go outside their houses. The people shout. They feel thirsty. After that, there's an earthquake.

#3 (8th graders)
It is the year 2113 and Anseong is a big city, but it has a problem. Subin, a 115 year old woman, is still alive. She is a witch. She is very strong so she has conquered Anseong. At the same time, a zombie virus has been spreading. Zombies are fighting people in Anseong. Some people have changed into zombies. Subin rides on a dragon and flies. At that time, the smart people learn that the zombies don't like light. The zombies go into a building. The people turn on the lights in the building. Subin falls off the dragon and dies. However, she revives, kills the zombies, and restores the building.

#2 (9th graders)
It is the year 2113, and Anseong, Korea is a big city, but it has a problem. Anseong is dirty so the people are sick. Most of the people have died. A doctor wants to cure the disease, but it's not easy. People listen to the doctor's words. Everyone drinks water and exercises everyday for a year. Some people get healthy. The doctor thinks all of the people are healthy, but the disease spreads to the rest of the world. The doctor feels that the problem is serious. The doctor searches for a new solution. The doctor says to never give up; however, all of the people die.

#1 (7th graders)
It is the year 2113, and the people in Anseong, Korea have a problem. Anseong is a very big city, but it is empty. The people weren't able to eat, so many people died. However, one man lives in Anseong. There's a subway station in Anseong. The man is very old. He goes to the subway station everyday to see if anyone else has come, but the station hasn't opened yet. The man is lonely. The man starts to cry. A train arrives at the station and a young man gets off. The young man eats an egg in the station. The young man and the old man never meet because the old man cried so much, he died. The young man creates new people. Anseong becomes very crowded again.
Here's a video of a character movie around an arena. The game is still early in it's development, but we've been making a lot of progress so far. A lot of the artwork that you see here is being refined and redone so we hope the final project will be really good.

Our team also has a new logo now. We will develop under Development Team Alpha Studios. How's the logo?

The blog post have been coming out fast these days. This is a video blog that will detail the process that I use when deciding on programming task. I still have a lot of coding to do so I have found the organization is very important when I want to get things done in a reasonable amount of time. More specifically, I need to work on various gameplay elements. The game engine internals are by no means set, but they are at a good enough level for me to focus on gameplay. Later, I'll work on improving things such as the graphics.

I'm also including an Excel spreadsheet of the template that I use.

Also, don't forget to check out the Auxnet: Battlegrounds project page
I have updated in a while, but that's because I've been coding like a mad man over the past few weeks. I had been working on adding PhysX and testing out collision detection, but the main work I've been doing has been adding basic multiplayer characteristics. It took me about 8 days, but now I've got basic peer to peer networking in using RakNet. It was a lot of work, but now multiple players can move around the level at the same time. I'm in Korea and my main partner is in America, but we were able to successfully connect and "play" together. Now I'm working on migrating the special effects system from my old engine and after that, I'll add the basic weapons system. My goal is to make this a fun playable game within the next few days, even if it requires a few all-nighters. The graphics are still a bit rough, but next week when we unveil everything, I hope it'll look a lot better. I'm still waiting on some artwork.

Here are some screen shots. I've done most of the multiplayer testing running two instances of the app on one computer. The first screen shot just shows a basic connection. The second shows two instances running on the same computer, but the game is also connected to a third computer in America over the Internet.