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.

Messages - Mjonir

Pages: [1] 2 3 4
General / Re: Making a Lua binding, questions
« on: June 07, 2012, 01:19:39 am »
Yay, I finally found out what makes it work! It took me hours of testing to isolate the cause as the behaviour seemed totally random.

To sum it up:
  • In general, no matter how I did it, compilation will crash when binding something with sf::WindowHandle, the trick mentioned in the link didn't seem to work.
  • It turns out that by great luck,  I tried binding the window in a file that included "Window.h" for completely unrelated reasons, and it worked!
  • I put everything back how it was and just included "Windows.h" in the file for window binding, and it worked as well.
To have it work in Lua, I also had to bind this:
luabind::scope register_WindowHandle()
    #ifdef BUILD_WINDOWS

and NOT sf::WindowHandle.

Here are updated, working sources: Download link

(By the way main.cpp in the previous archive was obviously the wrong one, sorry for that ^^')

Window executable demo using the handle at main.lua:21 and 22. The window "stops responding" however, not sure if that's normal behaviour or not as I've never played with these functions before.

It's really annoying that I'd have to make the binding OS-specific though, and it looks like it's going to bring lots of problems. Maybe it's better if I left it out of the binding, or only include it with a compilation option? :/

General / Re: Making a Lua binding, questions
« on: June 06, 2012, 11:05:39 am »
Weird... After a lot of testing I got it to compile (not tested yet) using this technique if and only if the binding of WindowHandler + Window is done and implemented in the file where I initialize Lua. If it's in any other file, the error reappears. I'll have to understand why before I move further.

I expect I should be able to work on this binding and release it this summer.

Thanks a lot for the extremely fast help as usual :)

General / Re: Making a Lua binding, questions
« on: June 06, 2012, 09:18:04 am »
WindowHandle is an opaque pointer on Windows, that you just need to pass around. You're not supposed to "use" (dereference) it. Can you show your code?

Here it is, it's a complete WIP though :)

See commented lines at binding/lua_registration_SFML_window.cpp:123, 126 and 146. I'm not sure what happens behind this though, it's all deep magic for me. If it helps, compiler errors on that line:

template <class T>
class_id const registered_class<T>::id = allocate_class_id(typeid(T));

With T = HWND__ I think. It looks like luabind needs to know.

Why don't you use a wrapper library such as luabind, which allows you to declare the binding in a very simple way?

I'm actually using luabind! :)

luabind v0.9.1 (latest) doesn't allow default values for parameters (was apparently scheduled for v1, but the project is not really maintained anymore). I've Googled it and the only solution seems to be function overloading.

Forget what I said about public inheritance though, I realized that in this case (since I'm not accessing anything private) I can just make static functions for each overload that accept a pointer to that SFML class and then bind them as if they came from the class. It'll be cleaner and easier even if not ideal. Still need to implement all these overloads though ^^'

Other problems I encountered with luabind were:

- No support for class attributes, I will probably have to wrap them all in static member functions. Maybe I can inject them again in their classes as attributes once luabind has finished.
- No support for operator[], which is really annoying! I think I'll just bind it to the __call metamethod in Lua, which is the equivalent of operator(), for the moment. Perhaps I can find a workaround using the Lua C API or something on the Lua side, I don't know yet :(

General / Making a Lua binding, questions
« on: June 06, 2012, 06:47:44 am »

For my game engine, I'm preparing a sort of Lua binding so that the scripter will be able to create and manipulate SFML objects directly.

I don't have much time at the moment and only started recently so it cannot do much yet, but here's a Windows executable version of the canonical demo translated in Lua: Download link.

What brings me here is a problem I encountered when trying to bind sf::Window, and more specifically its sf::Window(WindowHandle, const ContextSettings&) constructor. The problem here is WindowHandle, which gives me a compile-time error:

Code: [Select]
error: invalid use of incomplete type 'struct HWND__'
Looking a bit at the code of WindowHandle.hpp I tried to define _WIN32, but it didn't solve the problem. I'm not sure where to go from here, any hint Laurent? :)

Also as you can see, apart from constructors all functions calls have to be explicit (no support for default arguments). I think the only solution is to decompose all functions with default values to overloaded functions. I'd also like to define a getType() static member function for all SFML classes to do some dynamic typechecking and yield better error messages.

Since I'd like to avoid modifying the SFML source for obvious maintenance reasons, I'm thinking of creating a wrapper class for each SFML class that would inherit publicly and declare these new member functions. It'll be quite a bit of work though, so I'm wondering if anyone has got a better idea on how to do that before it's too late? :P

Thanks in advance!

Graphics / speed inconsistency (different computers)
« on: March 19, 2012, 09:30:23 pm »
Quote from: "N1ghtly"
This should do the trick, but I still strongly suggest using a fixed timestep!

Could you elaborate on this? Why would you ALWAYS use a fixed timestep?

Graphics / speed inconsistency (different computers)
« on: March 19, 2012, 08:19:49 pm »
Your problem is:

Code: [Select]
_velocity += 3.0f;

This line is executed every frame the player has the key pressed :)

Either assign a constant to "_velocity", or do something like:

Code: [Select]
_velocity += 3.0f * elapsedTime;

General / Simple Image Encryption
« on: March 18, 2012, 11:15:10 pm »
Quote from: "Mindful"

Like I said, I can't store them in the .exe (too many)

If was thinking on storing the headers in the .exe, not the whole picture. But you don't need that if you just remove a constant information ("89 PNG" which all PNG files start with).

but the idea of just removing the headers and extension sounds like something a little bit closer to my level. I'm sure I can find a tutorial on doing this to the files, but what would reading them afterwards look like? I take it I'd still have to use a custom InputStream?

To do that on the file, simply have a little program that open all ".png" files and remove the first 4 chars. (You can also test that it's not already removed, so you can just dump your images and run the same script without damaging images where the header is already removed.)

To read them, load the file in memory, add the little constant string at its beginning and then give it to SFML through loadFromMemory() methods. Can't give you the implementation, but that's the idea :)

General / Simple Image Encryption
« on: March 18, 2012, 10:56:19 pm »
Quote from: "nietaki"
It's also a good idea if you don't think your target audience will be persistant and read this thread.

On that subject, don't hesitate to PM me, if you want the idea to disappear, I'll gladly edit my previous message ;)

General / Simple Image Encryption
« on: March 18, 2012, 10:29:12 pm »
If you want something REALLY simple, why not just remove the headers + extension, and store them in your .exe? You can even just remove the mandatory "89 PNG" at the start of the file, most tools will refuse to open it, and you don't have anything to encrypt/store  :)

Graphics / Large RenderTexture class
« on: March 18, 2012, 12:35:03 am »
Quote from: "SoulBlade"
Just wanted to update, with some quick application of the views to the renderTextures I use, I can effectively make the "big" renderTextures I was talking about pretty easily.  Some minor quarks I need to work out, but wow, I feel pretty dumb.  Not to mention I've been doing my own transformations this entire time.  My brain chemistry is just not geared towards the common sense, I guess.  Probably why I'm a student physicist.  I appreciate the help, and apologize for taking time on such a simple matter.

Mind telling us that awesome technique you thought of? I'm curious now :P

Graphics / Re: Sprite layering
« on: March 15, 2012, 08:36:59 pm »
Quote from: "Nexus"
Is there a specific reason why you limit the Z ordering to custom classes? I mean, you could use sf::Drawable and work with anything that can be drawn (texts, shapes, custom drawables).

Speaking from experience, I don't think that's a good idea. Have a look at this recent topic (French forum).

To sum it up, Laurent commented on the issue: Base classes should not be used directly since he reserves the right to change them at any moment. One should at least build a layer of abstraction in order not to be too dependent upon that :)

General / Displaying Integers?
« on: March 15, 2012, 08:28:03 pm »
Sorry I'd like to help but I really don't understand. What do you mean by "C++ on the console can become a bad habit"?

From what I understand, you want to make a calculator where the user the user enters a mathematical expression, you evaluate it and display the result?

You can retrieve the input with the Keyboard-related classes of SFML. Treating the result however is pure programming and is an issue not related to SFML at all (but I'm sure you can find pretty good tutorials about making calculators).

The only thing SFML can do for you is allow you to create a window and then simply display images in it. However the way calculations are displayed is entirely up to you, that's something you have to invent.

General / Displaying Integers?
« on: March 15, 2012, 08:16:05 pm »
Well, SFML is "only" for displaying/playing/reading stuff. What's you're asking is not directly related to SFML so it's normal that's not covered in the tutorials. I'm also not sure what you mean when you say convert a console application?

I suggest you find tutorials on game design, I think that's what you really want to learn about :)

Anyway to answer your question if you want to display an integer in a window, I'd say the simplest way is using sf::Text?

Audio / Cannot find -lsfml-audio.dll
« on: March 15, 2012, 08:08:31 pm »
There are multiple step-by-step tutorials on the website, and I can ensure you they are correct. Just be sure to read everything and follow them to the letter :)

Sorry we can't really help you much more than this, the process is really straightforward, you must have made a mistake along the way. Don't hesitate to ask if there was something you did not understand though. If you're a bit lost, I suggest reading this recent post on the matter: http://www.sfml-dev.org/forum/viewtopic.php?p=48091&highlight=#48091

Graphics / Better way to draw same sprite multiple times
« on: March 15, 2012, 12:00:41 am »
Don't do that :o

What you want to do is make an array/matrix of sf::Sprite.

Use either a
Code: [Select]
and map them with id = x+LINE_SIZE*y or a
Code: [Select]
std::vector< std::vector<sf::Sprite> >

This way to can do:

Code: [Select]
sf::Sprite s = myMatrix[x][y];

Pages: [1] 2 3 4