Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - vipar

Pages: [1]
1
General / Data Driven Design: The Journey
« on: July 25, 2013, 12:01:11 am »
Hey guys!

I'd like to make this thread to dedicate what I learn about Data Driven Design (DDD for short) as I go along. This thread will also serve as a Questions thread to some of the, hopefully, more skilled people on these forums. It is done with the intention of learning and teaching at the same time.

I've written many applications in the past using Object Oriented Design (OOD for short). When I started looking into game programming it became apparent to me pretty fast that OOD just won't cut it. DDD is another way of making applications and it's a way I am not familiar with at all.
So I am starting from scratch trying to learn my way around DDD while making what I want.

My end-goal is to make a 2D Tile Engine, much the same as the one seen in A Link To The Past. Free Movement in all 8 directions, top-down, fighting and so on. This will take time and I am not going to become a wizard over night, I realize this.

So with that out of the way, lets start.
I've now read many articles on the subject of DDD. It seems that instead of using deep inheritance which discourages rapid change to the chain itself, you use Components and a flat structure which does not implement inheritance at all or at least, to a minimum. This is to reduce coupling and to make everything modular so you can plug-and-play what you want in the engine and game. You also focus on separating Logic from Data entirely. Finally you avoid hard-coding and also any game specific code so it's very reusable.

In my system I wanted to go for an Entity-System-Component (ESC for short) pattern. Every entity consist of component who each is just a bag of data. An Entity on it's own is nothing. Just an empty shell. No component have any behavior. The behavior is done in the Logic part since Components and Entities only act as Data.

For handling and managing entities and components there are Systems. Each System got it's own job and will be running Update() every frame. The EntitySystem will be making and removing entities. When an Entity is created it is given an ID expressed in an Integer. It also have all of it's Components given out to the respective ComponentSystems. Every frame of the game the EntitySystem calls Update() on all ComponentSystems which in return calls their Update() method as well, making everything update in a series rather than in a sequence (AAA, BBB, CCC instead of ABC,ABC,ABC).

Every Component implements the IComponent Interface so they can be grouped together in a List regardless of Component Type and every System implements the ISystem Interface so that the Update() method can be mandatory on all Systems should Expansion of the engine happen in the future.

Since this is a tile engine, some things will not be changed. There are Tiles which consists of a Vector2i for a Position and an Image which can be made into a Sprite at runtime seeing as Images can be saved while Textures in Sprites only exist temporarily. Levels consists of a 2D array of Tiles.

Here is a diagram of the design:

http://puu.sh/3KVcr.png

I would like to hear opinions on this approach.

2
DotNet / Embedding SFML into C#?
« on: May 24, 2013, 08:26:32 pm »
In C++ you can embed the Static Libraries into the application so you don't have to include them separately every time you make a new project in the output folder.

Is it possible to do the same in C#?

3
Graphics / Texture not Rendering on Screen
« on: May 23, 2013, 10:31:22 pm »
Here are the quick ones:

  • OS: Windows 7 64-bit Home Edition
  • GFX: ATi Radeon 6970
  • SFML Version: Using SFML 2.0
  • Dynamic or Static: Static

For some reason the Texture that I try to draw won't show up on screen.
My theory is that I point to a place in memory that is out of scope before usage. But I don't really know how to solve this. One solution might be to somehow use Smart Pointers but that didn't work out at all and there must be a more simple solution than this.

I am currently following a slightly out of date tutorial on how to make a simple Tile Engine with SFML 2.0 . In the tutorial he uses the Image type instead of Texture, but the problem I had with that, was that Image didn't have a Draw() method. So I switch it out for Textures. I am not sure if this would be the problem.

I don't get any errors, the texture just won't render on screen.

Here are the relevant bits from Engine.cpp:
bool Engine::Init()
{
        LoadTextures();
        window = new sf::RenderWindow(sf::VideoMode(800,600,32), "RPG");
        if(!window)
                return false;

        return true;
}

void Engine::LoadTextures()
{
        sf::Texture sprite;
        sprite.loadFromFile("C:\\Users\\Vipar\\Pictures\\sprite1.png");
        textureManager.AddTexture(sprite);
        testTile = new Tile(textureManager.GetTexture(0));
}

void Engine::RenderFrame()
{
        window->clear();
        testTile->Draw(0,0,window);
        window->display();
}

void Engine::MainLoop()
{
        //Loop until our window is closed
        while(window->isOpen())
        {
                ProcessInput();
                Update();
                RenderFrame();
        }
}
 

Bits from TextureManager.cpp
void TextureManager::AddTexture(sf::Texture texture)
{
    textureList.push_back(texture);
}

sf::Texture& TextureManager::GetTexture(int index)
{
        return textureList[index];
}

Tried to solve this for a little over 2 hours now.

4
DotNet / Code Tips and Movement?
« on: May 19, 2013, 03:09:19 am »
I would like both!

I am a noob and have just started using SFML for .NET!

So far it seems fairly simple to use for the kind of game I am doing to learn.
The game I am doing at the moment is a car going back and forth on the X axis and then I guess will be able to pick up points and stuff or simply just avoid objects coming towards the car until it eventually dies.

Someone said in another thread to me that I should have designed my program differently seeing as I was handling things somewhat wrong. Here is my code:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;

namespace SFMLCarGame
{
    class Program
    {
        private static RenderWindow window;
        private static Sprite car;

        static void Main(string[] args)
        {
            window = new RenderWindow(new VideoMode(256,512), "Car Game");
            window.Closed += new EventHandler(OnClose);
            window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);

            Sprite bg = new Sprite(new Texture("road.png"));
            car = new Sprite(new Texture("car.png"));
            car.Position = new Vector2f(window.Size.X / 2, window.Size.Y - 96);
            while (window.IsOpen())
            {
                window.DispatchEvents();

                window.Clear();

                window.Draw(bg);
                window.Draw(car);

                window.Display();
            }
        }

        static void OnClose(object sender, EventArgs e)
        {
            RenderWindow window = (RenderWindow)sender;
            window.Close();
        }

        static void OnKeyPressed(object sender, EventArgs e)
        {
            Vector2f newPos = new Vector2f(0, car.Position.Y);
            KeyEventArgs ke = (KeyEventArgs)e;
            if (ke.Code.Equals(Keyboard.Key.A))
            {
                if (car.Position.X != 0)
                {
                    newPos.X = car.Position.X - 8;
                    car.Position = newPos;
                }
                else if (car.Position.X < 0)
                {
                    newPos.X = 0;
                    car.Position = newPos;
                }
                else if(car.Position.X == 0)
                {
                    // Do nothing
                }
            }
            else if (ke.Code.Equals(Keyboard.Key.D))
            {
                if (car.Position.X != window.Size.X - 32)
                {
                    newPos.X = car.Position.X + 8;
                    car.Position = newPos;
                }
                else if (car.Position.X > window.Size.X)
                {
                    newPos.X = window.Size.X;
                    car.Position = newPos;
                }
                else if (car.Position.X == window.Size.X)
                {
                    // Do nothing
                }
            }
        }
    }
}
 

Probably got something to do with my Main() loop.

My second question is: How do I make the movement smoother? Currently the car will move 8 units first, before moving 8 units in the desired direction until I let go of the button. It's the same when I do it the other way. I would like it to just move instantly in the opposite direction if I switch keys.

Thanks in advance!

5
DotNet / A Classic Newbie Error Message (References missing)
« on: May 15, 2013, 10:59:36 pm »
Hey guys

I am new around here and wanted to start with something simple.
I know C# so it seems that SFML would be a nice start in game development!

I followed the Example in the SFML.Net API documentation file but I get an error about the DLLs:

Quote
An unhandled exception of type 'System.DllNotFoundException' occurred in sfmlnet-window-2.dll

Additional information: Unable to load DLL 'csfml-window-2': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

I am sure this is not the first one. It's probably all of the DLLs I included that will trigger this type of message. I read something about some kind of..config setup..? To bind the DLLs correctly. But I was not sure if this was necessary seeing as the documentation just threw a code example at me from the start :P

using System;
using SFML.Audio;
using SFML.Graphics;
using SFML.Window;

namespace SFMLExample
{
    class Program
    {
        static void OnClose(object sender, EventArgs e)
        {
            // Close the window when the OnClose event is received
            RenderWindow window = (RenderWindow)sender;
            window.Close();
        }

        static void Main(string[] args)
        {
            // Create the main window
            RenderWindow window = new RenderWindow(new VideoMode(800, 600), "SFML Window");
            window.Closed += new EventHandler(OnClose);

            // Load a sprite to display
            Texture texture = new Texture("cute_image.jpg");
            Sprite sprite = new Sprite(texture);

            // Create a graphical string to display
            Font font = new Font("arial.ttf");
            Text text = new Text("Hellow SFML.Net", font);

            // Start the game loop
            Music music = new Music("nice_music.ogg");
            music.Play();

            // Start the game loop
            while (window.IsOpen())
            {
                // Process events
                window.DispatchEvents();

                // Clear screen
                window.Clear();

                // Draw the sprite
                window.Draw(sprite);

                // Draw the string
                window.Draw(text);

                // Update the window
                window.Display();
            }
        }
    }
}
 

Pages: [1]
anything