clean minimalistic Quake C for schools

Discuss programming in the QuakeC language.
daemonicky
Posts: 185
Joined: Wed Apr 13, 2011 1:34 pm

clean minimalistic Quake C for schools

Post by daemonicky »

Quake C si simple. I though about what is bare bones Quake C.

Yesterday I thought that Quake C could be taugh at schools. Most likely secondary education ones. I mean, it is OOP and quite in the spirit of original OOP http://userpage.fu-berlin.de/~ram/pub/p ... kay_oop_en

Quake C has few states entity sets for simulation (model, movetype and nextthink) and few event handlers (think, touch and block). That is beautyfull. I thought that think and touch might be called timer and collision (or onCollision), but it just takes a habit to get used to. I guess that there might be some collisionmodel variable.

Quake C has event handlers where it is connected to the Quake engine :
Plus "only" places it is connected to Quake are these
void StartFrame(); ....
void PlayerPreThink(); ........ name makes sense but it is PlayerPrePhysics();
void PlayerPostThink(); ....... PlayerPostPhysics();
void ClientKill(); ................... GameQuit()
void ClientConnect(); .......... PlayerAdded()
void ClientDisconnect(); ...... PlayerRemoved()
void SetNewParms(); .......... PlayerSaveGame() , it is not regular save game though, but it handles saving of some net parameters, so why not handle event of player saving game ... I think it has been mentioned like
void SetChangeParms(); ..... ???
void PutClientInServer(); ..... ??? I dont know what this one means but thre might be on called LevelChanged() when player finishes level
void main(); ...... I never used this one and I do not know what it is good for

Some of them seems more or less useless to me (liek these which handle parameters ) and I tried to trim these handlers and change names:

Well. If player finishes level and is about to change to new one. What about saving the whole state to a save game? There has been some problems with *Parms handlers because they have dozen floats (?) which are transfered between levels.
On a new level, lot of entites will be destroyed. Of course. But some will remain, like a player. So they can retain some state. There may be problems in what to save and what not, becasue designers would not want some to save ... So I guess it would need a special handler - LevelChanged() and just set what should be transfered and what not or maybe somehow else, I do not know ...

So I came up with these :

void StartFrame(); ....
void PlayerPreThink(); ........ ~ PlayerPrePhysics(); ~ PlayerPreTimers()
void PlayerPostThink(); ....... ~ PlayerPostPhysics(); ~ PlayerPostTimers()
void PlayerAdded .......... when player starts single player or when player connect to a network game
void PlayerRemoved(); ...... if player kills himself or if he disconnects from network game
void PlayerSaveGame(); .......... called when player saves the game (for example : make players experience points lower if he saves :))
void PlayerLoadGame();
void LevelChanged(); ..... player finishes or starts level, mark what to save and what not. I guess best would be to say which stuff should be saved.

I think, that it is certailny not complete and I believe that it has to be tested on real kids (end-users) to came up with good design. What You think about it? I think that Quake C is so simple and that we can spread it. And lot of people can program in it, or maybe start programming in it (because making simple stuff is very direct here).

I dont know which data types to save either. Vectors, float and entities are must for any game. But there might be also some dictionaries (maps, hashes), lists (stacks, queues) and arrays.

USE CASE.... animation
I have not made animation in Quake yet so I dont know if its syntax is good. I guess it is. But is it also good for bone/skeletal animation?

USE CASE.... physics
I like dead simple set movetype/solid and physics is simulated. Wee need to gather use cases of physics to make the best one. Because from what I gathered lot of people are remaking Quake Physics a lot.

USE CASE.... saving stuff between levels
Changing of levels. I mean there is Oblivion/GTA with saving some stuff when loading new block of map and entering dungeon. And there is Quake with saving some stuff between levels. I dont know what syntax to make it with. Point is, "get inspired by best way the other games are doing it".

USE CASE ... AI
For example for searching the path.

for example lists are useful for AI to make decision treees and state space search. Well, but one can make special syntax for it. Do You remember frames used for ainamtion, I mean syntax which is special just like this for animations. You know, "this engine is Game ready, so it supports making AI blazingly fast just in your notepad. ". :)
ai wrote: base :
you set variables are in each state : state
you set transition functions which are just "rewriting pairs" : list of (state, state)
you set start and set of goals

= you need some event handlers like there_is_nothing_to_generate (you usually send monster to room it was previously searching for enemy) and ...
= such ai should be made as stepping function it will always offer you new possible moves or it will say it cant ... and you will realize animation of walking or something to fullfil these goals, if you did you just say "continue" to AI and if you failed somehow you may restart or cancel ai
USE CASE ... "I am new to Quake. I was using Game Maker (or similar) ..."
What about these guys. What do they like about GM/similar and what not. Get inspired.

I certainly forgot about some parameters and I do not know how to call tracelines and such, probably prefix them with "quake." or "qc." so one knows they all belong to one package of commands for Quake game. Because there might be differend games QuakeC might be good for, I just think that some other games might take use of it ... and if you would be looking at source than you will know which game it is using :) !

Well, I dont know ... threre should be barebones but AI and animations need special syntax, so make it barebones too :) .
qbism
Posts: 1236
Joined: Thu Nov 04, 2004 5:51 am
Contact:

Post by qbism »

Somewhere around is a "Quake from Scratch" or "scratch qc" series of tutorials, building up the qc code from zero.
Feared
Posts: 95
Joined: Fri Jun 11, 2010 11:58 pm
Location: Wylie, TX

Post by Feared »

qbism wrote:Somewhere around is a "Quake from Scratch" or "scratch qc" series of tutorials, building up the qc code from zero.
http://www.inside3d.com/qctut/scratch1.shtml
FrikaC
Site Admin
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Re: clean minimalistic Quake C for schools

Post by FrikaC »

daemonicky wrote: void StartFrame(); ....
void PlayerPreThink(); ........ name makes sense but it is PlayerPrePhysics();
void PlayerPostThink(); ....... PlayerPostPhysics();
void ClientKill(); ................... GameQuit()
void ClientConnect(); .......... PlayerAdded()
void ClientDisconnect(); ...... PlayerRemoved()
void SetNewParms(); .......... PlayerSaveGame() , it is not regular save game though, but it handles saving of some net parameters, so why not handle event of player saving game ... I think it has been mentioned like
void SetChangeParms(); ..... ???
void PutClientInServer(); ..... ??? I dont know what this one means but thre might be on called LevelChanged() when player finishes level
void main(); ...... I never used this one and I do not know what it is good for
So some correction/explanation, because I think these warrant a little.

StartFrame = Called by the game at the beginning of each frame. It's essentially global, unconnected with any entity. It can be used for checking for global game related conditions, such as the timelimit. Think of it like the world's think. Quake only used it to copy cvars over to globals for faster lookups, but it has many other uses.

PlayerPreThink/PlayerPostThink = Like you said called on either side of physics, but the name makes sense because it's also on either side of the .think() call (which happens during physics)

ClientKill = Called when a player uses the "kill" command in the console.

ClientConnect = Called when a player connects to the server.
ClientDisconnect = Called when a player disconnects.

SetNewParms = Called When a new client joins and no available saved parm information from a previous level exists.
SetChangeParms = Called when the level is about to change, so the QuakeC can make a determination on what it wants to save.

PutClientInServer = Called after ClientConnect when the player is actually ready to be spawned. The thing with connecting to a game is that there's some amount of time from when you connect and before you can actually spawn into the game. During this time, the server will allow you to chat and see chat from other players, but you need to download all reliable information about the game up to this point (the baselines). This is even more exaggerated in QuakeWorld with the downloading of assets. PutClientInServer signals the player is actually ready to start playing.

main() = It's a dummy function really, it's never called. Perhaps only for initial testing of the QuakeC system. It's use after was a dumping ground for precache calls that aren't actually run, they are just there so the QCC generation of PAK files will add them to the pak (most people don't use that feature of qcc, so I usually just blank the function out in all my code)
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: clean minimalistic Quake C for schools

Post by Cobalt »

Ah was looking for this, Nice - !

Additionally:

DecodeLevelParms () >>> This is called whenever you spawn at the next level.


The setspawnparms builtin [ void (entity e) setspawnparms = #78; ] refills the globals as they were when the player first entered the current level.

** I assume by "globals' they mean the parms.....
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: clean minimalistic Quake C for schools

Post by Cobalt »

Got a question for the guru's:

During either a:

Changelevel , restart or map command, is the global (time)== 0 ?
Or is nothing thinking except maybe startframe or Main () ?
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: clean minimalistic Quake C for schools

Post by Baker »

I'm pretty sure time starts at 1 second.

This is to avoid time 0. I think QuakeC uses time 0 to be "never do this", so if QuakeC ever encountered time == 0.00 then the consequences would be ... ugggh.

So it doesn't.

sv_main.c

Code: Select all

void SV_SpawnServer (char *server)
{
	edict_t		*ent;
	int			i;

...
	sv.paused = false;

	sv.time = 1.0; // <------- Where's Waldo?  Waldo is right here.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: clean minimalistic Quake C for schools

Post by JasonX »

I've thinking about this and started thinking about turning QuakeC into a weakly typed language, like PHP. This would decrease the learning curve and make it even more clean for newbies.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: clean minimalistic Quake C for schools

Post by Baker »

JasonX wrote:I've thinking about this and started thinking about turning QuakeC into a weakly typed language, like PHP. This would decrease the learning curve and make it even more clean for newbies.
QuakeC's learning curve is because it is explained very, very poorly. Everything I've seen focuses on technicalities, not the flow or how the "world inside Quake" works.

Oddly enough I can explain QuakeC pretty well now, without hardly any experience actually coding it because I tore apart pieces of my engine projects and built it back together.

It isn't hard. But the documentation and explanation of it sucks. At least from a beginner's point of view.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: clean minimalistic Quake C for schools

Post by mh »

I suspect that once upon a time time did begin at 1: there's a "host_time" variable in the engine which is initialized to 1 with a comment on it in Host_InitLocal: "so a think at time 0 won't get called". host_time appears to date from an earlier evolution of the engine and it's use has been completely relegated to the vcr system (does anybody actually use that?) and the totating "Q" logo in the menus - everything else uses realtime (or the appropriate cl.time or sv.time) and the remaining uses of host_time can be easily and painlessly replaced with realtime. Another instance of "multiple globals scattered throughout the engine all of which store broadly the same info and all of which must be kept in sync", although thankfully it's not as bad as some of the others that exist.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Re: clean minimalistic Quake C for schools

Post by frag.machine »

JasonX wrote:I've thinking about this and started thinking about turning QuakeC into a weakly typed language, like PHP. This would decrease the learning curve and make it even more clean for newbies.
Jesus, no. Please. All you'll manage with this is to make QuakeC SLOW. A string should born and dies as string, nothing more, nothing less.

That said, QuakeC VM's in general could learn a thing or two from other VM's like Java or .NET. Like, better support for temp strings. Some support to OO (doesn't need to use the Java/C# model, I would be fine with the Javascript "create an object and then clone it" approach). Remote debugging (that's requires an IDE, which is another important thing lacking). And maybe more hooks on critical engine points, like DP does to allow one to rewrite the game physics entirely in QuakeC.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: clean minimalistic Quake C for schools

Post by Cobalt »

Yea, the DP approach , at least to me right now, is the more attractive and challenging way to go....and though complicated in understanding , it seems LH has a fairly decent system going, with autobuilds happening every 3 weeks or whatever, and svn. I have not got a chance to get into the C too much for the engine, I am a QC guy really....but I can see one day having to take the next steps into learning more about it.

But the ' ground up ' approach to understanding the legacy engines can be very usefuyl before you get into these other engines I beleive, because its always possible someone who coded one of these engines overlooked something that worked in all other legacy engines. For example, I used the items2 float in my mod to do something unique with the runes in the hud back when I was working with plain ProQuake for example..and Darkplaces totally ignores items2 unless you run Rogue or Hypnotic. Since I reported the bug, LH has fixed it so that mod devs can use that float freely if need be. (took me months but it finally happened) Its just one example of how easy it is to overlook stuff no matter how long you have been at it. Was kinda surprised it too so long to get that corrected in the newest build, but I guess we got to remember Quake is not the number one priority in life....
frag.machine wrote: And maybe more hooks on critical engine points, like DP does to allow one to rewrite the game physics entirely in QuakeC.
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: clean minimalistic Quake C for schools

Post by Baker »

Cobalt wrote:Since I reported the bug, LH has fixed it so that mod devs can use that float freely if need be. (took me months but it finally happened) Its just one example of how easy it is to overlook stuff no matter how long you have been at it. Was kinda surprised it too so long to get that corrected
LordHavoc is outnumbered 739 to 1 by people asking for stuff.

Steel Storm, Xonotic, retexture people's, single player mappers, people that are making QuakeC mods, random DarkPlaces users, some guy somewhere whose DarkPlaces doesn't work on his computer, some guy somewhere running a server, probably a few Quakeworld people wanting some ezQuake features in DarkPlaces, and on and on.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: clean minimalistic Quake C for schools

Post by Cobalt »

Yes thats right. He ought to assign some ranks below him that can maybe handle some of the questions when busy. We got good people here, but with all the different engines around, not everything can be entirely asked here with a high chance of success in an answer anymore.

We need like a Quake internet browser or something..... :D
Baker wrote:
LordHavoc is outnumbered 739 to 1 by people asking for stuff.
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: clean minimalistic Quake C for schools

Post by JasonX »

Where can i find some documentation on the QuakeC VM and so on? I wanted to improve it's syntax a little bit and i wanted to know how much my changes would affect the VM. Basically, i would change the lexer in FTEQCC, right?
Post Reply