Jump to content

  • Log In with Google      Sign In   
  • Create Account

Squared'D's Journal

Latest Updates 2014-01-28 and Base64

Posted by , 27 January 2014 - - - - - - · 725 views
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.

Posted Image

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:

Posted Image

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

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

Posted by , 04 January 2014 - - - - - - · 2,003 views
c++, angelscript, stl, array and 1 more...
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.

template <class T, class TArrayClass = CScriptArray>
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:
// 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 <std::string> string_array;
// uses a user-defined array type called CScriptArrayInt
// this type should be a specialized version of CScriptArray that only handles integers
CScriptArraySTL <int, CScriptArrayInt> 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:

// Initializes the array so it can be directly accessed using AngelScript
// This must be called before the array can be used
int 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<int>".

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
// Create the script engine
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
// Register needed add-ons
RegisterScriptArray(engine, true);
// setup our string array
CScriptArraySTL <std::string> string_array;
string_array.InitArray(engine, "array<string>");
// register our array as a global variable in the script
r = engine->RegisterGlobalProperty("array<string> string_array", string_array.GetRef()); assert( r >= 0 );
// do other things and load and run scripts
// Release the array
// Release the script engine
Get the Source.
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.

// Constructors, Destructors and AngelScript initialization -------------------------------
// Initializes the array so it can be directly accessed using AngelScript
// This must be called before the array can be used
int InitArray(asIScriptEngine *engine, char *declaration, size_type init_length = 0);
// returns a pointer to an array class that can be used in an AS script
TArrayClass *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 array
size_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 smaller
void resize(size_type n);
// returns true if the array is empty
bool empty() const;
// grows the buffer capacity
void reserve(size_type n);
// iterators ----------------------------------------------------------------------------
// returns an iterator to the begining of the array
iterator begin();
// returns an iterator to the end of the array
iterator end();
// returns a constant iterator to the begining of the array
const_iterator cbegin() const;
// returns a constant iterator to the end of the array
const_iterator cend() const;
// returns a constant iterator to the begining of the array
iterator begin() const;
// returns a constant iterator to the end of the array
iterator end() const;
// returns a reverse iterator to the begining of the array
reverse_iterator rbegin();
// returns a reverse iterator to the end of the array
reverse_iterator rend();
// returns a constant reverse iterator to the begining of the array
const_reverse_iterator crbegin() const;
// returns a constant reverse iterator to the end of the array
const_reverse_iterator crend() const;
// returns a constant reverse iterator to the begining of the array
const_reverse_iterator rbegin() const;
// returns a constant reverse iterator to the end of the array
const_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 empty
reference front();
// returns a constant reference to the first element
// undefined if empty
const_reference front() const;
// returns a reference to the last element
// undefined if empty
reference back();
// returns a constant reference to the last element
// undefined if empty
const_reference back() const;
// Modifiers ------------------------------------------------------------------------------------
// adds a value to the end of the array
void push_back (const value_type& val);
// removes the last element
void pop_back();
// assigns new data to the array using iterators.
template <class inputiterator="">
void assign (InputIterator first, InputIterator last);
// fills the array 
void assign (size_type n, const value_type& val);
// clears the contents of the array
void clear()

Preview my new article

Posted by , 25 December 2013 - - - - - - · 941 views
article writing, angelscript, c++
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.

Latest Updates 2013-12-20

Posted by , in Auxnet 19 December 2013 - - - - - - · 656 views

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

Posted by , 08 December 2013 - - - - - - · 2,461 views
utf 8, utf8, utf-8, unicode and 1 more...
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.

Adding Attachment Models to Entities (with Video)

Posted by , in Auxnet 21 November 2013 - - - - - - · 1,069 views
skeletal animation, attachments and 5 more...
Adding Attachment Models to Entities

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.

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

A wiki that explains what skeletal animation is.

An old discussion on Gamedev.net about implementing a bone animation system.

A basic Skeletal Animation Tutorial

Feel free to check out my Google plus page for updates and check out my YouTube channel.
Google+: Squared'D Game Google+ Page
YouTube: Squared'D Youtube Channel

Middleware and 3rd Party Libraries in Auxnet - Part 2 - PhysX

Posted by , in Auxnet 13 November 2013 - - - - - - · 1,237 views
nvidia, physx, game development and 4 more...
Middleware and 3rd Party Libraries in Auxnet - Part 2 - Phys X
Posted Image

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:
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

Posted Image

Posted Image

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

Posted by , in Project B, Auxnet 01 November 2013 - - - - - - · 873 views
auxnet, middle ware, middleware and 2 more...
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.

Posted Image

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

Posted by , in Creative Writing 31 October 2013 - - - - - - · 889 views
teaching english, students and 4 more...
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.

Auxnet:Battlegrounds 2013-10-25 Prealpha Video

Posted by , in Project B, Auxnet 24 October 2013 - - - - - - · 814 views
auxnet, project b
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?

Recent Comments

January 2017 »

151617181920 21