Monday, July 27, 2015

Bug in rendering of editor

Week ago I wrote post about porting editor to linux. I was mentioning there this weird bug :
Editor works (Yes I know that drawing area is shifted to right. This is one of bugs that I still don't know why happening and I already spend on it like two days :/)
Which is really nicely visible on this screen shoot:


I spend on it like three days and still wasn't able to figure out why it happening or find any trace of it. I tried to ignore it but after noticing similar issues with blender and chrome I decided on desperate step. 

From my experience I know that upgrades of system never ending good. This is the reason why I try avoid them as much as it possible. But well sometimes you need to do stupid things so I decided to update my Linux (Ubuntu 14.04) and graphics card drivers (fglrx-14.301) to newest versions.

What went good: I was nicely surprised that system upgrade went without bigger problems. There were two steps 14.04 -> 14.10 -> 15.04 which took some time but except that I cannot complain.

What went wrong: Update of graphics card drivers. This is sad that after all this years you are not able to install driver without any problems. It took me half day of work, checking a lot of pages and in the end modifying source code of driver to make it work. This was just one line of code but still :/

Final result: Well decide yourselves:


It work how it should work but well I hate bugs like this. If I knew update of system would fix that I would spend 1 day on update not 3 days searching blindly what I doing wrong.

But well this is our developers reality: dealing with our bugs and bugs of others.

Greg

Saturday, July 18, 2015

Scripting language in game ....

I know I know I stepping on thick Ice. Some people love scripting languages other hate and other don't care. Personally I still don't know to which group I belong.

I somehow understand all sides:

  • Scripting language:
    • [+] Have quick iteration time
    • [+] Non programmer can do some simple stuff
    • [+] It's easier than native code
    • [+] Separate game from engine
    • [-] Can be slow (most of the time is)
    • [-] Use garbage collector so it was more user friendly 
    • [-] Can be tricky to debug.
  • Native code:
    • [+] Can be really efficient
    • [+] Give you access to everything
    • [+] You have full control
    • [+/-] No garbage collector
    • [-] Can get easily messy
    • [-] Easy thing can take really a lot of time
    • [-] Slow iteration time
    • [-] You need really good programmers to utilize it
Because I'm not 100% sure about using scripting language in game I will try to create some add-on to engine so you could use scripts but you weren't forced to do this if you want. 

And here start my dilemma and request for advice: 

Which script language you would like to use create game and why ? 

There is big choice of them C#, Lua, Python, Java Script (This one I would like to avoid) or maybe something completely different? I will be happy to hear your opinions.

Greg

Friday, June 19, 2015

Understanding of problem

This topic came to my mind in meantime of resolving linking problem on Linux. When I build dynamic library my app missed some of the symbols. 

And no I didn't forget to compile *.cpp file which contain it. If it was so easy I wouldn't spend hours on resolving it. But this won't be topic of this post. The topic is about understanding of problem that we try resolve. I talking especially about this weird situations when something happening and we don't know why.

I know different schools how to deal with this hard problems :] 

Conclusion 1: It's for sure not in my code. 

And this issue wasn't in my code :]  I didn't believed that this code was wrong from start. It was my fault for sure. Question only where. 

Of course I'm not always was this way. In my younger days very often after hour of searching I were deciding it's for sure not my fault. Of course in 99% of time I was finding out later that I was wrong. Well privilege of being young.

Conclusion 2: Let's shuffle code and it will work.

Not literally but point of this is to do some change which we think will fix issue but we don't understand why. After this we run application if it work we are happy. To give example we have crash in application because of NULL value so we add check if it is null.

Sadly this way of resolving problems is one of the worse I can imagine. There is nothing worse than changing randomly code because we try to resolve some issue. This is just bad idea because very often this "fix" hide real problem. With time passing finding steps to reproduce it became harder and harder.

Conclusion 3: Let's understand what happening.

I think is the best solution but have one bottleneck: it consume time. But I will add from my experience: that very often it save time later. Issue is resolved properly, we understand what we done to make it work and finally if it will reported again most of the time it's some other problem.

Conclusion 4: I understand what happening but don't know why.

This is my current situation where I know that my issue is because of linking of static libraries (*.a) inside dynamic (*.so). Static library missing virtual table symbols because one of virtual function is not in the same *.cpp. So I know why this issue happen I expect that there are some missing flags of linking to resolve it. I just need to find which one :]

Summary

Of course all this sound easy :] but its not. There are situation where you need to do null check because there is no time. You need to ship something in hour and there is no choice. Of course good approach is to look into the problem deeper after sending build to find real issue.

Other thing is that life showing that sometimes problem is really in some external library or not your code. This happening but still safer is to assume that you done something wrong. And if you really don't know what you could do wrong prepare some solid test case and contact person responsible for this piece of code.

Finally, approach to understand problem is not something we are born with (in most cases). This is for sure not the easiest way of dealing with problem and we need to put a lot of effort into it. But with time it start to being natural approach which bring only benefits.

Greg

Saturday, June 6, 2015

Lets play : Good code / Bad code

If you try to find answer what good/bad code is, you won't find it in this post. I don't try to sell my beliefs and I'm sure you wouldn't like them anyway. To show you that, check this simple pieces of code:

//////////////////////////////////////////////////////////////////////////
void CAnimationResource::releasevoid )
{
    SAFE_DELETE(m_privateData);
}

I use void when function don't use any arguments. I know this useless and do nothing but I just like look of it (Personal preference). Other example:

//////////////////////////////////////////////////////////////////////////
CAnimationResource::CAnimationResourceconst wrResourceIDa_idIResourceManagera_manager )
    : CResource(a_id)
    , m_manager(a_manager)
{
}

I using prefix a_ for arguments of functions and use this style of organizing initialization in constructors. This is my way of coding. You probably have your own style this is perfectly fine. We shouldn't fight over some conventions details. Everybody is different and everybody code differently. This is sometimes not easy to accept (even for me) but we just need to live with it. 

So let's not focus on programming style and move to the main topic:

Good code

So what good code really mean ? Some time ago I would probably give answer right away. It would be long and boring talk how to write code, what to do and what not to do. But right now I'm doubt I could easily answer this question.

Lets assume that we have piece of code which resolve some issue. Code is really messy with hacks all over it. Because of all this we cannot call it good code, great candidate to refactoring. Sadly without rewriting half of other big system it's hard to create better solution. People with commercial experience know that in production environment you not always can rewrite everything.

Following all this thoughts we can have bad code in which we have bad code which in given situation is the best possible code. So probably we could call it good code which don't make sense at all :| I'm lost in my thoughts.

So is this mean that bad code is good ?

I think it's just like problem mentioned in this presentation. The same gray tiles looks brighter  in shadow but in light area they look darker. I think this is accurate description of code. Our way of code perception is affected by code we know. Bad code may look pretty good if you deal with even worse code all the time.

So what bad code mean ?

Everybody recognize bad code when they see it. But defining it is not easy. For me there are few points which make code bad for me (this is my subjective opinion):
  1. If you spend more than hour to understand small piece of code and still fail to do it.
  2. Code show no understanding of problem it should resolve.
  3. Code with weird dependencies which are hard to follow.
  4. Duplicating of functionality that can be simple achieve by modification other piece of code.
  5. Overusing allocations.
  6. Not strict access rights to class members.
There is probably hundred more points which I missed. But this are the one that came to my mind right now.

Conclusion

So Good and Bad code is hard to define. Some "good" code that I wrote few years ago look for me crappy right not. Sometimes it's really bad piece of code and it's perfectly fine. If I'm saying this then it mean I'm better now and I can see flows in what I done. At some point when I will find time or need I will try to improve this bad code.

If in work somebody telling me that my code is bad. It mean that it's bad no matter how I see it right now. I will ask why he think so, we will discuss this mater and I will try to fix it. There is point in arguing who is right and who is wrong. It's about understanding why other person see my code as bad and dealing of source of problem.

Of course it's easier to talk about it then do it. We are often stuck in our boxes which are comfortable and don't try look outside. But there is outside world and we cannot forget about this. That's why I learned that I need to experience as much as I can. Different code, different technologies, different languages, different opinions, different approaches. I'm not always succeeding in that but I try and this is what allow me to grow.

What you think about this problem? And how to deal with it?

Greg

Sunday, May 24, 2015

Project generator

I like to experiments and have fun doing that. Right now I work on another crazy idea. You know because developing of game and technology behind is not enough. Don't worry this is just another side project connected with this one. 

Project generator.

I know that I could use some existing solutions (i.e CMake) but this wouldn't be so fun as doing it myself in python :] Well I started doing ... some time ago and returning to it whenever I had some time. Right now I'm at the level where Linux make support is better than previous generator I use. Sadly Microsoft Visual Studio support not exist there right now :D

Well I fix this in future. But lets move to some details about new project generator which is wrote in python.


Sunday, May 17, 2015

Singleton pattern

Singleton pattern... People love it or hate it. There are also group of people who don't mind them.

I'm still try figure out which I'm :] I'm for sure not the one who love them. I'm also cannot say that I rally hate them because I still use them in code (It is like with my Facebook account. After I created one I try not complain about fb. ). So probably I'm best fit to don't mind group.

But my past experience showing me that I have bigger tendency to removing them from code than adding new one. And probably some colleagues from work will be happy about this because we spend a lot of time discussing about problem.

I remove them because I put even more effort in good design of systems. In a lot of cases thanks to changes I just don't need global objects. Which is good. It allow me to better utilize multithreading thanks to encapsulation.

Today sadly I had problem where I still don't know cleaner solution than global state:

//////////////////////////////////////////////////////////////////////////
template<> bool write<CResHandle>( ISerializerWritera_writerconst CResHandlea_value )
{
    return a_writer.serialize(a_value.isValid() ? a_value->getId() : wrResourceID());
}

//////////////////////////////////////////////////////////////////////////
template<> bool read<CResHandle>( ISerializerReadera_readerCResHandlea_value )
{
    wrResourceID id;

    if (!a_reader.deserialize(id)) return false;

    if (CResource::isValid(id))
    {
        a_value = getResMgr()->createResource(id);
    }
    else
    {
        a_value = nullptr;
    }

    return true;
}

Function getResMgr() return global resource manager. I don't want to pass it around inside arguments because this is ugly and I would need to do the same with each manager I want to use. This would increase my arguments list and each new manager would recommend changes in all write/read functions.
I thought maybe about storing inside ISerializerReader/ISerializerWriter function like setData()/data() in some Qt classes. This way it will be really easily to extend list of available data even by game (which may add some new write/read functions). 

I'm still not sure about this solution and how nice it is. I will spend some time thinking about it but for now I will leave getResMgr() use with nice macro call right before it : 

WR_TODO("gwojciechowski""Think about way to not use global getResMgr().");

If you have any idea, thoughts or you just want to comment this. I'm open on opinion how to make this nice and clean :]

Greg 

Sunday, May 10, 2015

Sculptures gallery moved

To make my life simpler I moved my sculptures gallery to my deviant art account. You can find link in Arts page or here :

http://angelusda.deviantart.com/

UI

It's funny that only with time and experience you start to understanding how hard UI code is. I remember a lot of situations when UI freeze in meantime of doing something. Whole window is locked and you just prying that its still alive.

First version of my tools were similar: everything happening in one thread which was block when I was doing some longer operation. Because there was not too much to process it was not so painful. With time this changed, amount of data grow. To fix the issue I started adding progress bars to some operations and was happy.

Sadly I was still wrong. This solution is still messy. I block whole UI and just update progress bar when some operations may be processed in background. Recent change of threading taught me beaut of asynchronous operations.

Right now all my communication Engine <-> UI is happening by events which cleaning my design of whole tools. All code where I mix UI with mechanics changing in creation of event and processing of it later. Bellow you can see code creating event:

if (autoevent = m_appCtx->createEventT<CEditorEventGetLevelProperties>())
{
    event->setLevelSessionID(m_levelID);
    event->setUserData((size_t)a_properties);
    m_appCtx->submitEvent(eventfuncEventCallback()
                                 .connect(this, &QWrPropertiesEngine::onRequestTreeEvent));
}

Later I just need to process returned callback:

void QWrPropertiesEngine::onRequestTreeEventCEditorEventa_event )
{
    if (EErrors::isFailed(a_event->getErrorCode()))
    {
        return;
    }

    QPropertiesWidgetproperties = (QPropertiesWidget*)a_event->getUserData();

    Q_ASSERT(properties);

    autoevent = WR_RTTI_CAST_PTR(IEditorEventPropertiesa_event);

    Q_ASSERT(event);

    properties->clear();
    ...
}

I like this approach so much that I will probably switch in game UI on the same basics. How it will go we will see but for now I fell that this is good decision.

Greg

Monday, April 27, 2015

Dancing with code ?

I'm thinking if "dancing with code" could accurate describe my current situation with project. I started to think about it because I feel a little like student of dancing classes. You know this where they say you some things like:

Three steps forward, two steps back, Three steps ...

I'm still not sure if this is good phrase and also what kind of dance I would learning. But I know that with time it start to look better. So its my code. Sadly with each  new element I see there is still a lot for me to learn/do.

Sunday, April 19, 2015

Code review story ...

Last week I took small break from project. I get out of town, visited friend, meet new people and talk in meantime of drinking beer. Big part of this talks were about game programming (Yes I'm a geek and even after work I still talk about games and programming).

But why I telling all this ? Because this one week proved me how much I changed in last years and also how much I need to change in incoming ones.

This post will be be story about : How I thrown childish pride and became who I am.