Working!

I haven’t had any time to do any programming because of school and work. I want to get back to creating libraries, and updating them; however, I simply dont have the time for it. Perhaps at the end of July, I can get back to writing code. Until that time, dont expect any new code or updates.

video

In case anyone has not seen the two videos by Herb Sutter, “atomic Weapons: The C++ Memory Model and Modern Hardware,” go watch it now. It is a fantastic video that covers what atomics mean, how they are used, and where technology is supporting them. The information in this video will change your life guaranteed –or your money back!

Gems

So, I am working on integrating my UI system with my graphics system and I came across a very common problem of how to connect two completely separate modules. For example, when a model is loaded in a 3d world and the user selected the 3d model, I want have a tool pop up that is connected to the 3d model.

The tool can be position, scaling, texture info…. what ever. The point is that the GUI has some general purpose widgets like sliders that would be great to hook into the object in the world and update themselves. Well, if I pass the widget the memory address of the position, as floats, then I can keep the GUI decoupled — perfect. But, what happens when the 3d object is destroyed, how will the GUI widget know and take appropriate action? If the widget tries to read from the memory after the 3d object is destroyed, there will be an error.

One solution is to create some type of event manager that is tied into all parts of the program and acts as the glue. Then all of these objects: the GUI widget and the 3d object can communicate through this “middle man” and our safe communication can be achieved. When a 3d object is destroyed, it cal tell the event manager, which can then pass that message along to other objects that are listening for it. I really really don’t like this type of a plan. see http://www.gamedev.net/topic/638088-global-event-manager-system/ for a little discussion on the negatives posted by Hodgman, which I agree with.

Having said that, I came up with a simple solution which you can view here Signal.h

So, what is this? First, you need to be using a c++ 11 compliant compiler and with visual studio that means compiling using the nov compiler CTP you can get here http://www.microsoft.com/en-us/download/details.aspx?id=35515

So, here is the basic idea of the Signal class.

You have Library A and Library B of which neither know anything about the other. For example, a GUI and an in game 3d object. You want the widget to display the 3d objects position in the game world. Well, imagine if that 3d object is an NPC in a video game and it is walking around. Your widget needs a way to know when that 3d object has moved and act appropriately.

Also, it would be nice if this way was SIMPLE and didnt require any global managers, or any other fancy trickery. Enter my Signal class Signal.h

Below is a simple example of how to use it to glue together your libraries. In the example below the objects call the others functions. When one is destructed, the link is removed. You can connect as many objects together as you like.

class object_3d{
public:
	object_3d(){x=y=z=0.0f;}
	~object_3d(){
		On_Destruction.Call();
	}
	void  MoveTo(float newx, float newy, float newz){
		x =newx;	
		y =newy;
		z =newz;
		On_Moved.Call(x, y, z);// let anyone listening know that this object has moved
	}

	float x, y, z;// object_3d's position

	MY_Utilities::Signal_st<void, float, float, float> On_Moved;
	MY_Utilities::Signal_st<void> On_Destruction;
};

class gui_widget{
public:
	gui_widget(){x=y=z=0;}
	~gui_widget(){On_Destruction.Call();}

	void Update(float nx, float ny, float nz){
		x=nx;
		y=ny;
		z=nz;
		On_Update.Call(x, y, z);//let anyone who is bound to this know that the GUI changed the objects coords. So, the On_Update.call will let the object know
	}

	float x, y, z;

	MY_Utilities::Signal_st<void> On_Destruction;
	MY_Utilities::Signal_st<void, float, float, float> On_Update;
};

int main(int argc, char* argv[])
{
	object_3d obj;
	gui_widget widget;

	obj.On_Moved.Connect(&widget.On_Update, std::bind(&gui_widget::Update, &widget, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}

If you look in the example you might think that I created an infinite loop. When the 3d object calls On_Moved in the MoveTo Function, the guiwidgets Update function will be called. BUT WAIT, the Update function calls the 3d objects MoveTo — theres an infinite loop! Take a look in the Call Code of the signal class. In fact, ill post it here

		void Call(T... params){
			if(_Is_Calling) return;//avoid infinite recursion
			_Is_Calling = true;
			for(auto i=Slots.begin(); i!= Slots.end(); i++){
                               if((*i).first->Is_Calling()) continue;
			       (*i).second(params...);
			}
			_Is_Calling = false;
		}

If you see, when Call is called _Is_Calling is set to true, then for each connection, the remote function is checked to see if it is calling. If it is, the slot is skipped because all of the connections are a 1 to 1 so this check prevents infinite recursion.

When the Signal destructor is called, the connections are cleared on both ends. There is a st(single thread) version and an mt(Multi-thread) version. Of course, the single threaded is faster because there are no locks.

Something different

This post is for anyone who is a web developer, using mvc, and wants to share views between different projects.

This is very easy process and will enable you to have  completely modular parts to your website. Some common parts of a website can be the authentication code, error pages and generation, and others. So here is how you can put the controller(this process is not needed for controllers, they can be put into a library without anything special like this) and views into separate projects, and add a reference to them in the main project to use them –cool, isn’t it? I am going to assume a brand new solution because that’s easier, but the process is the same for an already existing solution you just have to do some moving around of files.

Create a new mvc website, this will be your main project –make sure its a website.

Add a new project to the solution –make sure its also a web site.

The reason for not creating the second solution as a class library is that if you were to do that, intellisense wont work in your views within it. So, make sure and create this as a website project!

Within your second project, delete the junk: app_data, content, Models, Scripts, and Global.asax.  You dont need these and you cant use the content, scripts, or global.asax anyway.

Now, you should just have Controllers and Views in the project.

Add the second project to the first project as a reference.

Now, install what makes views be incorporated into the second projects generated dll. Right click the second project and goto manage nuget packages. Goto online search for RazorGenerator.mvc. Install that.

RazorGenerator.mvc will compile your views and place them into the dll for the project. Now, you have many views in the second project that would cause a conflict if they were introduced into the main website because these files are there too. That doesnt matter yet because the views in the second project will not be included in the dll just yet.
To do that, goto the second project and find the Index.chtml view. Right click it, goto properties.

In the custom tool spot, put     RazorGenerator

Close the properties window. Now, an arrow should appear beside the index.html. If you click it, a cs file will appear. Thats the compiled version of your index.chtml. Views will only be included in the dll after you specify that custom tool for each one. This is annoying, but not as annoying if you are having to copy views between projects every time theres a change.

Now, Delete the controllers folder from the second project as well. If you dont, the controllers will conflict with the ones in the first project. You could rename them if you want to prevent that.

Moving on . . . open the index.chtml from the second project and replace

To learn more about ASP.NET MVC visit

with

To learn more about how to create shareable views

Goto the first project and find the Index.chtml file and delete it. We are going to use the view from the second project to show that it works!

Your all set now. Build and run your FIRST project. You should see the modified index.chtml showing.

Once think you might have noticed if you did this locally: there are two servers runnning. . .  what the hell?!?

Easy fix, shut down both. Highlight the second project.

If you are using VS 2010, goto View -> Properties window

If you are using VS 2012, goto View -> Other Windows-> Properties window

They like moving things around for different versions.

Where it says always start when debugging = true.   Set that to false. This will prevent each web project from starting up a server when the main project is debugged.

 

Thats it.. Have fun!

 

 

All code moved to github

All of the code has been moved to GitHub https://github.com/smasherprog/Destination_Toolkit

More improvements were also made to the codebase.

-Fixed the camera where it would begin to roll due to floating point precision.

-Changed the camera class to be virtual so different types of cameras can be set easily.

Started work on a UI widget to help with selecting game world objects.

 

Mesh loader working

I just got the Mesh loader working for static mesh. Next is animated mesh. However, first I will continue to improve the static mesh loader so Maps can be added after the model is loaded, and other features.

Check out the Google Code repository by clicking the Code button above. Instructions on how to get all the code is also available.

Let me know of improvements that can be made. . .

Fire Demo Added

A fire demo was added to the codebase and I am beginning work on a model loading example as well. The model loader is almost finished, just a few things to wrap up.

Particle demo added

A particle Demo has been added to the code repository. The release notes say it all. There were alot of changes and I have a hard time of noting them all, but most were general improvements to existing functions.

Support for Stream Buffers were added to the Graphics_Lib.

Shaders only recompile if there were a change, this saves HUGE on load time.

So, Check it out. . . .

Exe files added

I decided to add the 32 bit release build exe’s as part of the SVN. They are located in the 32_bitBuilds directory.  If you do not have visual studio 2012 installed, you will need to install the Microsoft visual studio 2012 redistributes. These are also included in the svn in Assets/RunTime   Install the 32 bit version (vcredist_x86.exe) if you are just checking out the executables.

Sky Dome and Ocean

A Sky Dome example was added to the Repository, and more UI controls were added to the ocean Example.