Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Who Needs Direction?

This thread is locked; no one can reply to it. rss feed Print
Who Needs Direction?
Don Freeman
Member #5,110
October 2004
avatar

Quote:

So I've been thinking of adding a check that makes sure the script hasn't sent a bad pointer. This could be costly though, any ideas on how this should be done?
Even if it's costly, we could at least include this check in debug.

To Trezker:
Maybe here????

I think I fix the first problem I was having, but now I get:

Init.lua:6: attempt to perform arithmetic on global 'x' (a function value)

[Init.lua]

player = Get_player(game)
x = Player_get_x_position(player)
y = Player_get_y_position(player)
print(x)
print(y)
Player_set_position(x+10,y+100)

[/Init.lua]

[main.cpp]

1#define ALLEGRO_USE_CONSOLE
2#include <allegro.h>
3#include "Lua_wrapper.h"
4#include <cstdlib>
5#include <iostream>
6#include <string>
7 
8Lua_wrapper lua_wrapper;
9class Player
10{
11public:
12 Player(){ x = y = 0; }
13 ~Player(){}
14 int X( void ) { return x; }
15 int Y( void ) { return y; }
16 void Set_position( int _x, int _y ){ x = _x; y = _y; }
17 int x, y;
18};
19 
20void Player_register_lua_callbacks(lua_State* state);
21 
22int Player_get_x_position(lua_State* state);
23int Player_get_y_position(lua_State* state);
24 
25 
26int Get_Player(lua_State* state);
27 
28int main( int argc, char **argv )
29{
30 Player *player = new Player;
31 if ( !player )
32 return 1;
33 lua_wrapper.Init();
34 lua_State* state = lua_wrapper.Get_state();
35 lua_register(lua_wrapper.Get_state(), "Get_player", Get_Player);
36 Player_register_lua_callbacks(lua_wrapper.Get_state());
37
38 lua_setglobal(state, "game");
39 lua_pushlightuserdata(state, player);
40 lua_wrapper.Load_script("Init.lua");
41 lua_wrapper.Deinit();
42 delete player;
43 player = NULL;
44 return 0;
45
46 allegro_init();
47 set_color_depth(32);
48 set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0);
49 install_timer();
50 install_keyboard();
51 install_mouse();
52 show_mouse(screen);
53 while ( !keypressed() );
54 return 0;
55}END_OF_MAIN()
56 
57int Get_Player(lua_State* state)
58{
59 std::cout<<"Get_Player(...)\n";
60 return 0;
61 //return NULL;
62}
63 
64int Player_set_position(lua_State* state)
65{
66 std::cout<<"Player_set_position(...)\n";
67 Player* player = static_cast<Player*>(lua_touserdata(state, 1));
68 
69 int x = lua_tonumber(state, 2);
70 int y = lua_tonumber(state, 3);
71
72 player->Set_position(x, y);
73 
74 return 0;
75}
76 
77int Player_get_x_position(lua_State* state)
78{
79 std::cout<<"Player_get_x_position(...)\n";
80
81 Player* player = static_cast<Player*>(lua_touserdata(state, 1));
82 if ( player )
83 lua_pushnumber(state, player->X());
84 
85 return 2;
86}
87 
88int Player_get_y_position(lua_State* state)
89{
90 std::cout<<"Player_get_y_position(...)\n";
91
92 Player* player = static_cast<Player*>(lua_touserdata(state, 1));
93 if ( player )
94 lua_pushnumber(state, player->Y());
95 
96 return 2;
97}
98 
99void Player_register_lua_callbacks(lua_State* state)
100{
101 std::cout<<"Player_register_lua_callbacks(...)\n";
102 //lua_register(state, "Player_set_position", Player_set_position);
103 lua_register(state, "Player_get_x_position", Player_get_x_position);
104 lua_register(state, "Player_get_y_position", Player_get_y_position);
105}

[/main.cpp]

Don't mean to hijack thread...just want to learn this LUA so I can help...:D

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Erin Maus
Member #7,537
July 2006
avatar

Trezker said:

This could be costly though, any ideas on how this should be done?

To do so, give the pointer (a.k.a. userdata) a metatable that's stored in the registry. Then, before executing commands, check to make sure that the provided userdata has the correct metatable. As long as the user doesn't use the debug library (you can just open the libraries manually and only have the debug library in debug mode) to change the userdata's metatable, all will be fine and dandy.

Example code is like so (not tested):

1/* In the Lua state setup function... You can add an index method or
2 * whatever else you need, for example to do something like "Entity.X"
3 * instead of "Entity_get_x(Entity)"
4 */
5void Lua::Initialize(lua_State * L)
6{
7 luaL_newmetatable(L, "Entity");
8 lua_pop(L, 1);
9}
10 
11/* In the creation function for pushing the userdata. I would recommend,
12 * and do use (when I use plain C or don't use LuaBind), a "wrapper"
13 * struct/class for this, like so:
14 *
15 * struct Userdata
16 * {
17 * public:
18 * ILua * Userdata; // Or void *, but this is somewhat "safer"
19 * bool Shared; // If this shouldn't be collected by the Lua
20 * // state
21 * }
22 *
23 * However, I will not use this for the example.
24 */
25
26 /* This could also be "Entity::Push" or something similar. */
27bool Lua::PushEntity(lua_State * L, Entity * entity)
28{
29 Entity ** e = (Entity **)lua_newuserdata(L, sizeof(Entity **));
30
31 luaL_getmetatable(L, "Entity"); /* Remember the Entity metatable
32 that was created earlier? Yep. */
33 lua_setmetatable(L, -2);
34
35 *e = entity;
36
37 return true; /* You can check for errors if you need to add more
38 to this function. */
39}
40 
41/* Lastly, to get the entity, you do this: */
42Entity * Lua::GetEntity(lua_State * L, int position)
43{
44 Entity ** e = (Entity **)luaL_checkudata(L, position, "Entity");
45
46 return *e;
47}

Of course, you'll need to use "heavy" userdata, and not that light pointer stuff.

This will ensure that, unless the user does something stupid (like below) in the Lua script, everything will operate correctly and there is no way a normal modder/whatever can cause the game to crash.

debug.setmetatable(Something_create(0, 0), debug.getregistry().Entity)

I hope this helps!

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

Trezker
Member #1,739
December 2001
avatar

Well, that is rather cryptic technobabble, and lots of pointers...

And I need three things.

Create_entity - function that creates an entity in C++, puts it in the entity manager and returns a handle to the new entity.

Destroy_entity - function that removes an entity from entity manager, this is quite safe as it is...

various interaction functions - needs to be able to tell if the handle sent from lua is an entity that exists in the entity manager.

The simplest way to solve the problem would be to just ask the manager if the pointer is in the managers entity container using a std::find. I'm just wondering if that'd risk being way too slow.

Don Freeman
Member #5,110
October 2004
avatar

Unless we load all scripts that we need at once (not to run-just check), process to see if they are correct, if not we abort...if so we can continue with the game.8-)
Edit:
This way we can keep things from breaking our systems, yet the run time will be quick. Of course this could be a problem if the user changes the scripts while running...but then we could store md5 checksums after the check in process to keep that from happening.:D

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Paul Pridham
Member #250
April 2000
avatar

Matt (et al.), here is the bulk of the speech synth stuff I have collected, as promised.

Some of your strange animated mouth project is in there with my original Speechy stuff, as well as a bunch of datasheets, allophones, various text-to-speech code, formant synthesizer code, and others. Most of it is public domain.

Enjoy! :)

23yrold3yrold
Member #1,134
March 2001
avatar

Ooooh, actual work has been done! Debugging and testing! Didn't even occur to me we were far enough along to warrant that! Yay! :D

In other news, my tilemap editor sure slows the crap down if you load a decent sized tilemap image into it. :( Still working on that, but I figured out how to deal with animation editing ...

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Neil Black
Member #7,867
October 2006
avatar

By the way, I'm still here when you guys need playtesters.

Don Freeman
Member #5,110
October 2004
avatar

I've noticed strange behavior with the animations...like it is "off" by 1-2 pixels in the width of the images or that the bitmaps are not being cleared to a mask color before being loaded with animation data that does not completely fill the bitmap. Also, I get a segment fault every time I run the program and exit. Doesn't matter if I am just in the menu, or actually in the game. I've noticed problems with the menu code for the keyboard section. You can move up and down the menu, but sometimes the menu goes psycho and "loses" it's start and end positions. I will look at the code later...8-) Also, I've got a TON (over 150MB) of weapon sounds in ogg format...very high quality. These are hand guns, rifles, machine guns, explosions, rockets, etc. Someone just let me know what ya want, or if I get SVN write access...it will be included in my branch.::)

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

MiquelFire
Member #3,110
January 2003
avatar

Wow, it will suck when you upload that, and when others download your branch for the first time.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

Don Freeman
Member #5,110
October 2004
avatar

I don't HAVE to upload all that...someone could just request what they want to include...::)

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

bamccaig
Member #7,536
July 2006
avatar

Yeah, could always post it elsewhere and let the team figure out which files they do want... Or if MiquelFire can spare 150MB, you could upload them into a separate wpnsndfx branch, and files could be fetched from it with svn export.

:-/

Don Freeman
Member #5,110
October 2004
avatar

I have another group that is only about 3mb in rar format...I'll just include it. It has a lot of sounds in it...8-) Almost forgot about it! :)

Also, found some old civil defense posters...like fallout shelter info, etc. Government issue, so is public domain.;D

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

MiquelFire
Member #3,110
January 2003
avatar

I made a folder you can put stuff like that in the repo. I won't mind the occasional 150MB or so file actually. Just big really big file in that one directory to not hurt those on slow connections (including slow DSL).

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

Don Freeman
Member #5,110
October 2004
avatar

I've uploaded the smaller one (3mb) and some posters from old civil defense. I think I am doing something wrong...it was included in the trunk...not MY branch! :( What am I doing wrong?!? I am using kdesvn if that helps. Also, it will not upload my include/src directories correctly...I thought only MY branch would be added...no touch to the trunk.

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

bamccaig
Member #7,536
July 2006
avatar

Don Freeman said:

I think I am doing something wrong...it was included in the trunk...not MY branch! :( What am I doing wrong?!? I am using kdesvn if that helps. Also, it will not upload my include/src directories correctly...I thought only MY branch would be added...no touch to the trunk.

When you checkout a repository path a working copy is created on your machine that represents the repository structure. You need to put things in your working copy path exactly where you want them to be in the repository. For example, if you have checked out the repository to ~/src/monday, and you wanted to add your files to ~/src/monday/rawdata/wpnsndfx you might...

cd ~/src/monday/rawdata
svn mkdir wpnsndfx
cp ~/mywpnsndfiles/*.ogg wpnsndfx
svn add wpnsndfx/*

Before committing to the repository, you should always check the output of svn status (kdesvn surely has this somewhere), which will tell you which files have been added, modified, or deleted; or are unversioned. This way you can review your structural changes before committing them.

MiquelFire
Member #3,110
January 2003
avatar

There's a move command that changes where your working copy is pointed to.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

Don Freeman
Member #5,110
October 2004
avatar

Quote:

When you checkout a repository path a working copy is created on your machine that represents the repository structure. You need to put things in your working copy path exactly where you want them to be in the repository.

I DO have the structure layed out correctly...or at least I thought so.
This is the layout I have:

The Monday Project/monday/branches/donald/Monday:
[include]
[media]
My Branch Notes.txt
[obj]
[Release]
[src]
Story.html
Weapons.html
[wip_media]

I think kdesvn screwed something up with the structure...???

When I first started, I just checked out the SVN state as it was, created a branch called donald, and created EVERYTHING in that folder ONLY!

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

bamccaig
Member #7,536
July 2006
avatar

MiquelFire said:

There's a move command that changes where your working copy is pointed to.

svn switch

???

To find out information about a local or remote item you use the svn info command. From inside a working copy directory, with no arguments, it should tell you the remote URL of the directory.

Don Freeman
Member #5,110
October 2004
avatar

MiquelFire:
Is there a way that you could move this stuff into MY branch ONLY...this way I can fix what I have here and then try again????

Edit:
I think I will only use the command line svn instead...the kdesvn is confusing...since I never used svn before, well...not to ADD stuff anyway.::)

Edit2:
Ok...I fixed the SVN...I will upload my stuff later. Sorry everyone.::)

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

Trezker
Member #1,739
December 2001
avatar

I see there's a ton of files in your branch under wip_media. If you merge, these files will end up in wip_media in the trunk...

The wip_media folder really shouldn't be under trunk or under a branch.

Don Freeman
Member #5,110
October 2004
avatar

I've got the stuff uploaded...

also, I noticed (and fixed) the code in the keyboard menu that was causing the fuc@ ups I was having. The corrected code is:
(in the keyboard menu source file)

    switch (event.keyboard.keycode)
    {
    case ALLEGRO_KEY_UP:
      option--;
      if (option<0) option=3;
      break;
    case ALLEGRO_KEY_DOWN:
      option++;
      if (option>3) option=0;
      break;

I can't seem to actually PLAY the game...I get the main_menu_option = 0, but nothing happens. I can go into the other menus fine... We need to fix the problem of the game exiting when you are backing out of the key/joystick configuration...it SHOULD just go back to the main menu.8-) Also...I still get the segment fault EVERY time I run it...no matter what!:(

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

bamccaig
Member #7,536
July 2006
avatar

Trezker said:

The wip_media folder really shouldn't be under trunk or under a branch.

It would be fine in a dedicated branch, but not in one where project development is going on. I think that's why MiquelFire created /rawdata.

Matt Smith
Member #783
November 2000

Sorry if anyone thinks the new /ma5king dir is intrusive. Apart from revision numbers it won't interfere with us in any way. It was the quickest way to get ma5king into SVN and it would be great to use for all the GUI, even the ingame stuff.

Don Freeman
Member #5,110
October 2004
avatar

Fine with me...
The segfault all the time error, must be some lib compat problems on the lappy. I am not having any issues on the desktop...same OS, so...I must have done something different with the allegro libs.:P

Argh, Back to work maities!:D

--
"Everyone tells me I should forget about you, you don’t deserve me. They’re right, you don’t deserve me, but I deserve you."
"It’s so simple to be wise. Just think of something stupid to say and then don’t say it."

OnlineCop
Member #7,919
October 2006
avatar

With everyone working on slightly different things in their own branches, is everything in the "trunk" considered to be the "stable branch" that we can/should help out with bug fixes?

For example, trunk/src/Character.cpp, line 28 is:
Lua_wrapper *wrapper = game->Get_lua_wrapper();
However, game->Get_lua_wrapper(); doesn't return a pointer; it returns the reference to the local variable (g++ reports "src/Character.cpp:28: error: cannot convert 'Lua_wrapper' to 'Lua_wrapper*' in initialization").

If we find things like this, is it safe to assume that we should go ahead and fix it?



Go to: