Irrlicht (Cross platform 3d game engine) Client

What would you like to see in Freeciv? Do you have a good idea what should be improved or how?
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Irrlicht (Cross platform 3d game engine) Client

Post by Elefant »

I noticed that a while back there was some interest in making a desktop 3d client, but it always seemed to focus on making the webgl client work on a desktop. I don't know much about c++ coding, but maybe it would be easier to make an all-new client based on a 3d game engine. Of the game engines I looked at, the Irrlicht game engine has some features that make it a possible choice. First, it is cross-platform, and can be compiled on windows, linux, and osx. It also has many different renderers, including two software renderers, meaning it can run on any computer, regardless of if the computer has opengl. Most importantly, the license is gpl2+ compatible (at least, a major game based on it, tuxcart, is released under this license, and minetest, another game based on it is released under the gpl compatible MIT license).

Some features listed on their website:
High performance realtime 3D rendering using Direct3D and OpenGL [more]
Platform independent. Runs on Windows, Linux, OSX. Further platforms are in development and already used in projects.[more]
Huge built-in and extensible material library with vertex, pixel, and geometry shader support [more].
Seamless indoor and outdoor mixing through highly customizeable scene management. [more]
Character animation system with skeletal and morph target animation. [more]
Particle effects, billboards, light maps, environment mapping, stencil buffer shadows, and lots of other special effects. [more]
Several language bindings which make the engine available to other languages such as C#, VisualBasic, Delphi, Java …
Two platform and driver independent fast software renderers included. They have different properties (speed vs. quality) and feature everything needed: perspective correct texture mapping, bilinear filtering, sub pixel correctness, z-buffer, gouraud shading, alpha-blending and transparency, fast 2D drawing, and more.
Powerful, customizeable, and easy to use 2D GUI System with Buttons, Lists, Edit boxes, …
2D drawing functions like alpha blending, color key based blitting, font drawing, and mixing 3D with 2D graphics.
Clean, easy to understand, and well documented API with lots of examples and tutorials.
Written in pure C++ and totally object oriented.
Direct import of common mesh file formats: Maya (.obj), 3DStudio (.3ds), COLLADA (.dae), Blitz3D (.b3d), Milkshape (.ms3d), Quake 3 levels (.bsp), Quake2 models (.md2), Microsoft DirectX (.X)… [more]
Direct import of Textures: Windows Bitmap (.bmp), Portable Network Graphics (.png), Adobe Photoshop (.psd), JPEG File Interchange Format (.jpg), Truevision Targa (.tga), ZSoft Painbrush (.pcx)… [more]
Fast and easy collision detection and response.
Optimized fast 3D math and container template libraries.
Directly reading from (compressed) archives. (.zip, .pak, .pk3, .npk)
Integrated fast XML parser.
Unicode support for easy localisation.
Works with Microsoft VisualStudio, Metrowerks Codewarrior, Bloodshed Dev-C++, Code::Blocks, XCode, and gcc 3.x-4.x.
The engine is open source and totally free. You can debug it, fix bugs and even change things you do not like. And you do not have to publish your changes: The engine is licensed under the zlib licence, not the GPL or the LGPL.

Here is the license for it:
Copyright © 2002-2010 Nikolaus Gebhardt

This software is provided ‘as-is’, without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
And here is a link to the website:https://irrlicht.sourceforge.io/?page_id=45
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Irrlicht (Cross platform 3d game engine) Client

Post by Elefant »

Started trying to make a client. Here's my code so far.

Code: Select all

#include <irrlicht.h>
#include <IGUIButton.h>
#include "driverChoice.h"
#include <IGUIEnvironment.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

struct SAppContext
{
    IrrlichtDevice* device;
    s32             counter;
    IGUIListBox* listbox;
};

// Define some values that we'll use to identify individual GUI controls.
enum
{
    GUI_ID_NEW_GAME_BUTTON = 101,
    GUI_ID_LOAD_GAME_BUTTON,
    GUI_ID_LOAD_SCENARIO_BUTTON,
    GUI_ID_NET_GAME_BUTTON,
    GUI_ID_SETTINGS_BUTTON,
    GUI_ID_QUIT_BUTTON,
};

class MyEventReceiver : public IEventReceiver
{
public:
    MyEventReceiver(SAppContext& context) : Context(context) { }

    virtual bool OnEvent(const SEvent& event)
    {
        if (event.EventType == EET_GUI_EVENT)
        {
            s32 id = event.GUIEvent.Caller->getID();
            IGUIEnvironment* env = Context.device->getGUIEnvironment();

            switch (event.GUIEvent.EventType)
            {
            case EGET_BUTTON_CLICKED:
                switch (id)
                {
                case GUI_ID_QUIT_BUTTON:
                    Context.device->closeDevice();
                    return true;

                case GUI_ID_NEW_GAME_BUTTON:
                {
                    //Context.listbox->addItem(L"Window created");
                    Context.counter += 30;
                    if (Context.counter > 200)
                        Context.counter = 0;

                    IGUIWindow* window = env->addWindow(
                        rect<s32>(100 + Context.counter, 100 + Context.counter, 350 + Context.counter, 200 + Context.counter),
                        false, // modal?
                        L"New Game");

                    env->addStaticText(L"This Feature doesn't work yet .Please close me",
                        rect<s32>(20, 35, 230, 50),
                        true, // border?
                        false, // wordwrap?
                        window);
                }
                return true;


                case GUI_ID_LOAD_SCENARIO_BUTTON:
                {
                    //Context.listbox->addItem(L"Load Game");
                    // There are some options for the file open dialog
                    // We set the title, make it a modal window, and make sure
                    // that the working directory is restored after the dialog
                    // is finished.
                    env->addFileOpenDialog(L"Please choose a scenario map.", true, 0, -1, true);
                    return true;
                }

                case GUI_ID_NET_GAME_BUTTON:
                {
                    //Context.listbox->addItem(L"Window created");
                    Context.counter += 30;
                    if (Context.counter > 200)
                        Context.counter = 0;

                    IGUIWindow* window = env->addWindow(
                        rect<s32>(100 + Context.counter, 100 + Context.counter, 350 + Context.counter, 200 + Context.counter),
                        false, // modal?
                        L"Network Game");

                    env->addStaticText(L"This Feature doesn't work yet. Please close me",
                        rect<s32>(20, 35, 230, 50),
                        true, // border?
                        false, // wordwrap?
                        window);
                }
                return true;

                case GUI_ID_SETTINGS_BUTTON:
                {
                    //Context.listbox->addItem(L"Window created");
                    Context.counter += 30;
                    if (Context.counter > 200)
                        Context.counter = 0;

                    IGUIWindow* window = env->addWindow(
                        rect<s32>(100 + Context.counter, 100 + Context.counter, 350 + Context.counter, 200 + Context.counter),
                        false, // modal?
                        L"Client Settings");

                    env->addStaticText(L"This Feature doesn't work yet .Please close me",
                        rect<s32>(20, 35, 230, 50),
                        true, // border?
                        false, // wordwrap?
                        window);
                }
                return true;

                case GUI_ID_LOAD_GAME_BUTTON:
                {
                    //Context.listbox->addItem(L"Load Game");
                    // There are some options for the file open dialog
                    // We set the title, make it a modal window, and make sure
                    // that the working directory is restored after the dialog
                    // is finished.
                    env->addFileOpenDialog(L"Please choose a save file.", true, 0, -1, true);
                    return true;
                }

                default:
                    return false;
                
                }
                break;

            case EGET_FILE_SELECTED:
            {
                // show the model filename, selected in the file dialog
                IGUIFileOpenDialog* dialog =
                    (IGUIFileOpenDialog*)event.GUIEvent.Caller;
                //Context.listbox->addItem(dialog->getFileName());
            }
            break;

            default:
                break;
            }
        }

        return false;
    }

private:
    SAppContext& Context;
};
int main()
{
    // ask user for driver
    video::E_DRIVER_TYPE driverType = driverChoiceConsole();
    if (driverType == video::EDT_COUNT)
        return 1;

    // create device

    IrrlichtDevice* device = createDevice(driverType,
        core::dimension2d<u32>(800, 600));

    if (device == 0)
        return 1; // could not create selected driver.

    device->setWindowCaption(L"Irrlicht Engine - Freeciv Client Test");

    video::IVideoDriver* driver = device->getVideoDriver();
    IGUIEnvironment* env = device->getGUIEnvironment();

    video::ITexture* bg = driver->getTexture("client/bg.png");
    video::ITexture* intro = driver->getTexture("client/intro.png");
    gui::IGUIFont* font = device->getGUIEnvironment()->getBuiltInFont();
    gui::IGUIFont* font2 =
        device->getGUIEnvironment()->getFont("client/fonthaettenschweiler.bmp");
    IGUISkin* skin = env->getSkin();
    if (font2)
        skin->setFont(font);
    //set up the buttons
    env->addButton(rect<s32>(150, 400, 350, 400 + 32), 0, GUI_ID_NEW_GAME_BUTTON,
        L"New Game", L"Launch a new game");
    env->addButton(rect<s32>(150, 440, 350, 440 + 32), 0, GUI_ID_LOAD_GAME_BUTTON,
        L"Load Game", L"Load a saved game");
    env->addButton(rect<s32>(150, 480, 350, 480 + 32), 0, GUI_ID_LOAD_SCENARIO_BUTTON,
        L"Load Scenario", L"Loads a prebuilt map");
    env->addButton(rect<s32>(450, 400, 650, 400 + 32), 0, GUI_ID_NET_GAME_BUTTON,
        L"Network Game", L"Join a network game");
    env->addButton(rect<s32>(450, 440, 650, 440 + 32), 0, GUI_ID_SETTINGS_BUTTON,
        L"Settings", L"Client Settings");
    env->addButton(rect<s32>(450, 480, 650, 480 + 32), 0, GUI_ID_QUIT_BUTTON,
        L"Exit", L"Quit");

    // Store the appropriate data in a context structure.
    SAppContext context;
    context.device = device;
    context.counter = 0;

    // Then create the event receiver, giving it that context structure.
    MyEventReceiver receiver(context);

    // And tell the device to use our custom event receiver.
    device->setEventReceiver(&receiver);


    driver->getMaterial2D().TextureLayer[0].BilinearFilter = true;
    driver->getMaterial2D().AntiAliasing = video::EAAM_FULL_BASIC;
    while (device->run() && driver)
    {
        if (device->isWindowActive())
        {
            u32 time = device->getTimer()->getTime();

            driver->beginScene(true, true, video::SColor(255, 120, 102, 136));
            // draw background and splash
            driver->draw2DImage(bg, core::position2d<s32>(0, 0));
            driver->draw2DImage(intro, core::position2d<s32>(145, 50));

            env->drawAll();

            // draw some other text
            if (font2)
                font2->draw(L"Welcome to the experimental Irrlicht engine 3D client for freeciv.",
                    core::rect<s32>(250, 20, 650, 80),
                    video::SColor(255, 0, 0, 0));

            driver->endScene();
        }
    }

    device->drop();

    return 0;
}
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Irrlicht (Cross platform 3d game engine) Client

Post by Elefant »

And here are some screenshots.
Attachments
IrrCliCapture2.PNG
IrrCliCapture2.PNG (888.99 KiB) Viewed 10557 times
IrrCliCapture.PNG
IrrCliCapture.PNG (886.81 KiB) Viewed 10557 times
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Irrlicht (Cross platform 3d game engine) Client

Post by Elefant »

New game page started, but needs menus.
Also, this client currently has no way to talk to the server.
Attachments
IrrCliCapture3.PNG
IrrCliCapture3.PNG (896.84 KiB) Viewed 10543 times
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Irrlicht (Cross platform 3d game engine) Client

Post by Elefant »

Here's the code.
Attachments
V0.2.txt
(10.74 KiB) Downloaded 181 times
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Irrlicht (Cross platform 3d game engine) Client

Post by Elefant »

And here is a screenshot of what will become the map page, with a rotating earth model to demonstrate the 3d rendering.
Attachments
IrrCliCapture4.PNG
IrrCliCapture4.PNG (699.02 KiB) Viewed 10537 times
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
cazfi
Elite
Posts: 3069
Joined: Tue Jan 29, 2013 6:54 pm

Re: Irrlicht (Cross platform 3d game engine) Client

Post by cazfi »

Great!

Maybe it would be better to open a ticket about this, and attach the code there?

Please read doc/CodingStyle through, and try to follow that from the beginning, to minimize the need to rework all the style later.

I'll try to check that in more detail once I get the 3.0.2 release out of the way.
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Irrlicht (Cross platform 3d game engine) Client

Post by Elefant »

Unfortunatlly, as this is my first C/C++ program, and because I am learning on the fly, by cutting bits of code from the Irrlicht tutorials, and making it fit, the program is very messy, and beyond my skills to fix. It is also more of a demo of some of the features needed to make a client, although it might be useful as a starting point for a client. At this point it would probably be easier to start fresh using gui-stub as a template.
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
Elefant
Hardened
Posts: 212
Joined: Sat May 28, 2022 3:55 am

Re: Irrlicht (Cross platform 3d game engine) Client

Post by Elefant »

Here's the final version, before I start working on a proper client.
Attachments
V0.3.txt
(14.82 KiB) Downloaded 187 times
Civ 3 tileset: viewtopic.php?t=92953
3d Irrlicht desktop client development: viewtopic.php?t=92289&start=20
cazfi
Elite
Posts: 3069
Joined: Tue Jan 29, 2013 6:54 pm

Re: Irrlicht (Cross platform 3d game engine) Client

Post by cazfi »

Elefant wrote: Fri Jun 10, 2022 2:13 pmAt this point it would probably be easier to start fresh using gui-stub as a template.
Then you may want to take https://osdn.net/projects/freeciv/ticket/44695 to your baseline.
Post Reply