Beginner's Delimma...

A place to discuss things that aren't specific to any one creator or game.
Forum rules
Ren'Py specific questions should be posted in the Ren'Py Questions and Annoucements forum, not here.
Message
Author
User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#16 Post by PyTom »

One thing to realize when programming these games is that you really shouldn't be programming a game. By this I mean trying to express the script of a game as programming language statements, as could be done by calling a function to display each line of dialogue.

This was the approach I tried in the very first version of Ren'Py, and one that I abandoned quite early. It basically makes it impossible to save and load the game, as most programming languages provide no facility for jumping back into the middle of a function. One can work around this by providing designated save points, but that's less than ideal.

Instead, you want to represent the game script as data, which is used to control some form of virtual machine. (Using the term quite liberally... bytecode seems to me to be massive overkill for this purpose.) By turning the control flow of the game into data that is manipulated by the engine, we can save the current control position, along with the game state, and fairly easily implement loading and saving.

As to language choice, I would choose a high-level language like Java or a VHLL like Python over a low-level language like C. Many of the higher-level languages have C-based libraries that handle the expensive graphics operations, and the remaining control stuff really isn't that important speed-wise.

(Indeed, it's generally worth spending some time being clever and trying to minimize the number of pixels that are blit to the screen. In my tests of Ren'Py, that's where most of the time is spent.)

Finally, one thing I've come to realize is how much harder coming up with a good script is, as compared to writing the game engine. :-)

Naraku
Newbie
Posts: 20
Joined: Mon Nov 15, 2004 3:27 pm
Contact:

#17 Post by Naraku »

So far all I have is Microsoft Visual J++ and a free C+ compiler.
Most books do not cover memory management or advanced I/O
for Java or C+. The use of arrays for game data and saveing,
loading game, and windows GUI is what I got hung up on.

I first started programing back in July 26, 1983 on a TRS80
useing Basic, then I got a Commadore128 on June 25, 1985
and used both Basic and 6502 Assembly code. On March 18, 1999
I built a IBM PC compatible piece by piece from individualy
purchased parts and have built two more IBM PC computers
since then and have recently started programing in Java.
I have yet to get the C+ compiler to work.

BlackSpider
Regular
Posts: 133
Joined: Fri Aug 22, 2003 1:08 pm
Location: Wroclaw, Poland
Contact:

#18 Post by BlackSpider »

Well, I got my first (ever) computer (a Commodore64) in June 1986. Those were the times :). Then I got my first PC in 1990. But in fact I really started programming in 1997. First I learned assembly, then in 1998 I learned C, then C++, and later other stuff like HTML, CSS...

Anyway, you already mentioned DevCPP as one of the free C++ compliers. Actually it's quite good, has a nice gui. I downloaded the package a month ago and I really like it. It looks like it's going to be my main Windoze C/C++ compiler now :).

Naraku
Newbie
Posts: 20
Joined: Mon Nov 15, 2004 3:27 pm
Contact:

#19 Post by Naraku »

I started out with Basic on TRS80 and Comodore128, that is
Basic with line numbers so I am a beginer at OOP like Java
and C++. I feel that OOP is too restrictive and doesn't allow
for individual programing style and is also weak, it doesn't
have direct access to memory, file input output, or graphics
and little support for arrays. Older versions of Basic had
extended commands for graphics, file input output, and
direct memory access, and even had a command for running
machine code subroutines from inside a Basic program.
I started trying to program in C++ useing Open Watcom
it was a Dos command line only nightmare, switching back and
forth between Dos and Windows gets old very quickly.
I never bothered to study Fortran because I considered it
to be a dead computer language, so I have no idea how
to use the free fortran compiler I got or even if its worth
takeing the time to learn how to use it.

BlackSpider
Regular
Posts: 133
Joined: Fri Aug 22, 2003 1:08 pm
Location: Wroclaw, Poland
Contact:

#20 Post by BlackSpider »

I'm not familiar with Java, but in C/C++ nothing stops you from accessing memory directly (even under Windows). However you need to lock the area of memory you want to access first to obtain a physical address. Besides, I don't really understand why you can't do file input/output, graphics or call machine code (assembler) subroutines from within a C++ program. It's all possible :). What you probably need is a good Windows (or DOS if you like) programming tutorial for C/C++ beginners. However seeing that you're not used to object oriented programming I'd advise you start learning clean C first.

Guest

#21 Post by Guest »

None of the beginner books cover those topics.
I have two books on C and three books on java
none of them cover memory access, arrays, or file input output
that was the worst $300 I ever spent. Remember the old
Commadore 64 users manual ? How all the commands were
laid out alphebeticly with a short discription of the command
and how to use it ? Why cant anyone publish a book like that
anymore ? I dont like wasting hours thumbing through a book
with no index for the information I need at the moment, and
I am sure nobody else does either....

Naraku
Newbie
Posts: 20
Joined: Mon Nov 15, 2004 3:27 pm
Contact:

#22 Post by Naraku »

BlackSpider wrote:I'm not familiar with Java, but in C/C++ nothing stops you from accessing memory directly (even under Windows). However you need to lock the area of memory you want to access first to obtain a physical address.
I am sure that it can be done but it's only like the most closely
gaurded programing secret there is...

Ho humm, I guess I will have to stick with Allegro's
premade routines...

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

#23 Post by PyTom »

Accessing memory directly with C is actually really easy. Just cast an integer to a pointer, and dereference that pointer, as in:

Code: Select all

char *foo = (char *) 0x12341234;
*foo = 42;
The problem with this is that it's basically useless on a modern operating system with memory protection. (Anything newer than MS-DOS.) This is because modern operating systems use virtual memory, which means that the address space of a process and the address space of the computer have little to do with each other.

This is why modern operating systems provide APIs and libraries for handling screen display, so you don't have to handle these details.

One of these libraries that's fairly nice is SDL http://www.libsdl.org, which abstracts out much of the hardware of interest to a game programer. Pygame takes this one step further by providing SDL functionality to a high-level language, freeing the user from having to worry about things like memory management.

BlackSpider
Regular
Posts: 133
Joined: Fri Aug 22, 2003 1:08 pm
Location: Wroclaw, Poland
Contact:

#24 Post by BlackSpider »

Wow, yet another Miko avatar :). Yes, SDL is the way to go if you want to create simpler games later on. Besides if you have problems writing a C/C++ function don't hesitate to ask here on the forums. I'm sure a few people (including myself) would help you.

Post Reply

Who is online

Users browsing this forum: No registered users