home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


Small Coding Question

by theomnis on 02/01/2005 06:50, 14 messages, last message: 02/06/2005 19:14, 1350 views, last view: 04/25/2024 02:36

Hello all, Im currently working a Cube powered RPG. I already have a couple of minor code changes in place, but there is one that just stumps me...which isnt too hard :P

What I want, is after a player triggers a trigger model, for it to wait a set period of time(10 seconds or so), then respawn.

Can anyone here help out, or at least point me in the right direction?

   Board Index   

#1: Sleep command

by tentus on 02/01/2005 18:05

There is, if my memory serves me right, a command, "sleep #", which delays the following command by # of milliseconds. It's limited though to a single "sleep" at a time, so you have to be clever if you want to rely on this heavily.

You wouldn't happen to be willing to post you're changes so far, would you? I could probably use any refernce that I can get.

reply to this message

#2: Close

by theomnis on 02/01/2005 20:54

Right now my code changes are limited to a total overhaul of the monsters, and a little tinkering with weapons.

The command is "Sleep(#);", and what that does is freeze the entire game for the inserted number of milliseconds. It comes close to what I want to do, but not quite.

Im currently trying to isolate the parts of the code that make ammo and armor respawn, and hopefully apply it to the carrot, but Im nto having much luck right now.

reply to this message

#3: Re: Close

by tentus on 02/02/2005 00:36, refers to #2

ah. yes, that would pose a problem. though i'm not sure that "sleep" freezes the whole game- I use it to make sound fx without actually making any new sounds.

reply to this message

#4: Re: Close

by pushplay on 02/03/2005 02:51, refers to #2

If I remember correctly, sleep() is responsible for having the process block for a period of time, which is clearly not what you want.

The most robust solution might be to create a vector of time delayed events, which would look like a struct of start, delay, and action. Each time step would look through the array to see if it is now later than start+delay and if you perform the action and remove it from the vector. Command itself could be a parseable string, or maybe a function pointer and arguments. Lambda calculus would be useful here.

Aard is the blackbelt coder here though. I'm green belt, green belt with a stripe tops. :)

reply to this message

#5: Re: Close

by tentus on 02/03/2005 02:55, refers to #4

what would that make a genuine 100% firsttimer? that's me :( oh well. read and learn

reply to this message

#6: ..

by theomnis on 02/03/2005 09:00

Yeah...I was hoping that there would be a simpler way to do something like that. As I already said, Im not the best coder, and I doubt I could do something like that. I will keep trying though.

reply to this message

#7: Re: ..

by pushplay on 02/05/2005 03:21, refers to #6

Just look up function pointers and the rest should be fairly straight forward. If you don't know how to implement this then I think it's even more important that you try. You won't be able to get much else done if you can't do this. I'm willing to answer small questions.

reply to this message

#8: Entity "thinking"

by angeles on 02/05/2005 08:19

Or, at least thats how the Quake world would term it. Basically you want a period of time to elapse before it does something. If you only want to apply this to entities, that makes the job even easier.

You basically want to set a time value on when this action will occur. The simplest way I have found is to create an 'int' value in the entity structure (take a look in cube.h) which I set to the next time this entity 'thinks' the next action, like:

entity.nextthink = lastmillis + 5000;

(I use this to a rather cool effect on my wormhole teleporters).

In your entity routine (or whatever, good place to start looking is renderentities in entities.cpp) you check if (lastmillis > entity.nextthink) and execute your action.

I know to the others that this may seem like a bit of bottlefeeding, but many people could benefit from a simple concise tutorial on this.

reply to this message

#9: ..

by tentus on 02/05/2005 20:29

ok, so i've been studying, messing with, and compiling cube this morning, and up until thirty minutes ago it was going swimmingly. I changed some of the values for monsters, weapons, and the filenames of those weapons. I recorded every change I made, in a text file, so that I would know what to undo if everything died. Feeling I had done enough, I stopped to eat some lunch. When I came back, Cube refused to run. Nothing had been changed since I had last run cube, right before I ate.

After some frustration, I decided to try retracing my steps. While this worked in a limited fashion, cube now insists on running in a window mostly offscreen. Trying to debug in Visual Studio, I keep on getting "loaded C:\WINDOWS\system32\whatever.dll, Symbol not found".

Anyone have any ideas as to what went wrong? Did I somehow switch something in studio that is affecting how it compiles? Again, I can make cube run, but only in a window 3/4 offscreen, and debugging is no help whatsoever.

reply to this message

#10: Re: ..

by tentus on 02/05/2005 20:31, refers to #9

If anyone wants it, I can post my changelog- the number of steps is very short, which may be the reason that cube's gone to pot. Maybe I forgot to record some essential step, though I'm pretty sure I didn't.

reply to this message

#11: Re: ..

by pushplay on 02/05/2005 20:48, refers to #10

Keeping a changelog is good, but a changelog plus versioning is even better. If you don't want to set up cvs just copy the full directory some where and give it a date.

reply to this message

#12: threads and wait()

by RogueHaxor on 02/06/2005 08:33

actually a good way to do it could be with wait(). SDL has a thread implimentation, which is used throughout the source codebase. in fact cube has a function just for creating new threads *I think* . So you'd set up your trigger, and then have it wait(asettablewaitvariable), and it would take in wait at void(char *trigger, int asettablewaitvariable) {
Then you just need to set up a void that takes in no data, that loops reading the socket looking for triggers.
then you can thread the void(void *).

Teh biggest potential bug I see in this method is that it would wait the entire trigger search thread when a trigger was hit. So maybe you could have it launch a new trigger search thread just before it waits, that will die once the wait returns.

reply to this message

#13: Re: ..

by tentus on 02/06/2005 15:28, refers to #11

Huh. Now that i've let my computer cool overnight, the problem seems to have fixed itself. perhaps it's a bug in my video card, and not my coding, b/c now i can't find any problem...

Damn you economy computer parts. Oh well, note to self, 'once find bug let computer cool for a few hours'.

reply to this message

#14: Re: ..

by D.plomat on 02/06/2005 19:14, refers to #13

lol, cheap hardware parts... I already lost some hours with a nasty RAM that made my... network card(!) hang after 6-7 hours... many kernels recompiled later with testing many different configurations, finally removing a RAM solved the problem, but that wasn't what i'd suspect, as everything else was working.

reply to this message

   Board Index   


Unvalidated accounts can only reply to the 'Permanent Threads' section!


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
53874141 visitors requested 71649369 pages
page created in 0.021 seconds using 10 queries
hosted by Boost Digital