Skip to content

Commit

Permalink
Merge branch 'vanilla' into PR-13
Browse files Browse the repository at this point in the history
  • Loading branch information
giulianobelinassi authored May 21, 2024
2 parents 3ee9442 + 5071cd6 commit 9572d10
Show file tree
Hide file tree
Showing 63 changed files with 761 additions and 511 deletions.
13 changes: 3 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,9 @@ if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Windows")
option(WIN9X "Enable support for Windows 95/98/ME." OFF)
option(DSOUND "Enable DirectSound audio. (deprecated)" OFF)
option(DDRAW "Enable DirectDraw video backend. (deprecated)" OFF)
option(SDL1 "Enable SDL1 video backend." OFF)
option(SDL2 "Enable SDL2 video backend." ON)
option(OPENAL "Enable OpenAL audio backend." ON)
add_feature_info(Windows9x WIN9X "Windows 95/98/ME support" OFF)
add_feature_info(DirectSound DSOUND "DirectSound audio backend (deprecated)")
add_feature_info(DirectDraw DDRAW "DirectDraw video backend (deprecated)")
add_feature_info(SDL1 SDL1 "SDL1 video backend")
add_feature_info(SDL2 SDL2 "SDL2 video backend")
add_feature_info(OpenAL OPENAL "OpenAL audio backend")
else()
add_feature_info(SDL1 SDL1 "SDL1 video backend")
add_feature_info(SDL2 SDL2 "SDL2 video backend")
set(OPENAL TRUE)
endif()

if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand All @@ -56,6 +46,9 @@ if(APPLE OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
endif()
endif()

add_feature_info(SDL1 SDL1 "SDL1 video backend")
add_feature_info(SDL2 SDL2 "SDL2 video backend")
add_feature_info(OpenAL OPENAL "OpenAL audio backend")
add_feature_info(RemasterTD BUILD_REMASTERTD, "Remastered Tiberian Dawn dll")
add_feature_info(RemasterRA BUILD_REMASTERRA "Remastered Red Alert dll")
add_feature_info(VanillaTD BUILD_VANILLATD "Tiberian Dawn executable")
Expand Down
2 changes: 1 addition & 1 deletion common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ set(COMMON_SRC
crc.cpp
crew.cpp
cstraw.cpp
connect.cpp
debugstring.cpp
delay.cpp
dipthong.cpp
Expand Down Expand Up @@ -157,6 +156,7 @@ endif()

if(NETWORKING)
list(APPEND COMMONV_SRC
connect.cpp
ipxaddr.cpp
wsproto.cpp
wspudp.cpp
Expand Down
2 changes: 1 addition & 1 deletion common/alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static size_t TotalRam = 0;
static unsigned int Memory_Calls = 0;

void (*Memory_Error)(void) = NULL;
extern void (*Memory_Error_Exit)(char* string) = NULL;
void (*Memory_Error_Exit)(char* string) = NULL;

/***************************************************************************
* Alloc -- Allocates system RAM. *
Expand Down
8 changes: 0 additions & 8 deletions common/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,9 @@ typedef enum
/*=========================================================================*/
/* The following prototypes are for the file: SOUNDIO.CPP */
/*=========================================================================*/
int File_Stream_Sample(char const* filename, bool real_time_start = false);
int File_Stream_Sample_Vol(char const* filename, int volume, bool real_time_start = false);
void Sound_Callback(void);
void maintenance_callback(void);
void* Load_Sample(char const* filename);
int Load_Sample_Into_Buffer(char const* filename, void* buffer, int size);
int Sample_Read(int fh, void* buffer, int size);
void Free_Sample(void const* sample);
bool Audio_Init(int bits_per_sample, bool stereo, int rate, bool reverse_channels);
void Sound_End(void);
Expand All @@ -133,13 +129,9 @@ bool Sample_Status(int handle);
bool Is_Sample_Playing(void const* sample);
void Stop_Sample_Playing(void const* sample);
int Play_Sample(void const* sample, int priority = 0xFF, int volume = 0xFF, signed short panloc = 0x0);
int Play_Sample_Handle(void const* sample, int priority, int volume, signed short panloc, int id);
int Set_Sound_Vol(int volume);
int Set_Score_Vol(int volume);
void Fade_Sample(int handle, int ticks);
int Get_Free_Sample_Handle(int priority);
int Get_Digi_Handle(void);
int Sample_Length(void const* sample);
void Restore_Sound_Buffers(void);
bool Set_Primary_Buffer_Format(void);
bool Start_Primary_Sound_Buffer(bool forced);
Expand Down
3 changes: 2 additions & 1 deletion common/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "base64.h"
#include <stddef.h>
#include "endianness.h"

/*
** This is the magic padding character used to fill out the encoded data to a multiple of
Expand Down Expand Up @@ -425,4 +426,4 @@ implementations.
within base64-encoded parts of multipart entities because no hyphen
characters are used in the base64 encoding.
*/
*/
2 changes: 1 addition & 1 deletion common/bfiofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void BufferIOFileClass::Free(void)
{
if (Buffer) {
if (IsAllocated) {
delete[] Buffer;
delete[] static_cast<char*>(Buffer);
IsAllocated = false;
}

Expand Down
19 changes: 8 additions & 11 deletions common/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

#include <stdio.h>
//#include <mem.h>
#include <sys/timeb.h>
#include <chrono>
#include <string.h>
#include "connect.h"

Expand Down Expand Up @@ -225,6 +225,8 @@ int ConnectionClass::Send_Packet(void* buf, int buflen, int ack_req)
((CommHeaderType*)PacketBuf)->PacketID = NumSendNoAck;
}

SwapCommHeaderType((CommHeaderType*)PacketBuf);

/*------------------------------------------------------------------------
Now build the packet
------------------------------------------------------------------------*/
Expand Down Expand Up @@ -745,7 +747,6 @@ int ConnectionClass::Service_Receive_Queue(void)
*=========================================================================*/
unsigned int ConnectionClass::Time(void)
{
static struct timeb mytime; // DOS time
unsigned int msec;

#ifdef WWLIB32_H
Expand All @@ -762,23 +763,19 @@ unsigned int ConnectionClass::Time(void)
/*------------------------------------------------------------------------
Otherwise, use the DOS timer
------------------------------------------------------------------------*/
else {
ftime(&mytime);
msec = (unsigned int)mytime.time * 1000 + (unsigned int)mytime.millitm;
return ((msec / 100) * 6);
}

#else

/*------------------------------------------------------------------------
If the Westwood library isn't being used, use the DOS timer.
------------------------------------------------------------------------*/
ftime(&mytime);
msec = (unsigned int)mytime.time * 1000 + (unsigned int)mytime.millitm;
return ((msec / 100) * 6);

#endif

static auto epoch = std::chrono::steady_clock::now().time_since_epoch();
auto now = std::chrono::steady_clock::now().time_since_epoch();
msec = unsigned(std::chrono::duration_cast<std::chrono::milliseconds>(now - epoch).count());

return ((msec / 100) * 6);
} /* end of Time */

/***************************************************************************
Expand Down
7 changes: 7 additions & 0 deletions common/connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
********************************* Includes **********************************
*/
#include "combuf.h"
#include "endianness.h"

/*
********************************** Defines **********************************
Expand All @@ -122,6 +123,12 @@ typedef struct
unsigned int PacketID;
} CommHeaderType;

inline void SwapCommHeaderType(CommHeaderType* cht)
{
cht->MagicNumber = le16toh(cht->MagicNumber);
cht->PacketID = le32toh(cht->PacketID);
}

/*
***************************** Class Declaration *****************************
*/
Expand Down
5 changes: 4 additions & 1 deletion common/file_posix.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include "file.h"

#include <string.h>
Expand Down Expand Up @@ -56,7 +59,7 @@ unsigned int Find_File_Data_Posix::GetTime() const
return 0;
}
struct stat buf = {0};
if (stat(DirEntry->d_name, &buf) != 0) {
if (stat(FullName, &buf) != 0) {
return false;
}
return buf.st_mtime;
Expand Down
1 change: 1 addition & 0 deletions common/fixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#define FIXED_H

#include <stdint.h>
#include "endianness.h"

/*
** This is a very simple fixed point class that functions like a regular integral type. However
Expand Down
13 changes: 7 additions & 6 deletions common/framelimit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ void Frame_Limiter(FrameLimitFlags flags)
#else
auto frame_end = std::chrono::steady_clock::now();
#endif
int64_t _ms_per_tick = 1000 / Settings.Video.FrameLimit;
auto remaining =
_ms_per_tick - std::chrono::duration_cast<std::chrono::milliseconds>(frame_end - frame_start).count();
if (remaining > 0) {
ms_sleep(unsigned(remaining));
unsigned int min_frame_time = 1000000 / Settings.Video.FrameLimit;
auto cur_frame_time = std::chrono::duration_cast<std::chrono::microseconds>(frame_end - frame_start).count();
if (cur_frame_time < min_frame_time) {
frame_start += std::chrono::microseconds{min_frame_time};
us_sleep(min_frame_time - cur_frame_time);
} else {
frame_start = frame_end;
}
frame_start = std::chrono::steady_clock::now();
}
}
19 changes: 19 additions & 0 deletions common/graphicsviewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,3 +980,22 @@ void GraphicViewPortClass::Draw_Rect(int x1_pixel, int y1_pixel, int x2_pixel, i
Draw_Line(x2_pixel, y1_pixel, x2_pixel, y2_pixel, color);
Unlock();
}

void GraphicViewPortClass::Texture_Fill_Rect(int xpos,
int ypos,
int width,
int height,
unsigned char* shape_pointer,
int source_width,
int source_height)
{
if (Lock()) {
for (int y = ypos; y < ypos + height; y++) {
for (int x = xpos; x < xpos + width; x++) {
LogicPage->Put_Pixel(
x, y, *(shape_pointer + ((y % source_height) * source_width) + (x % source_width)));
}
}
Unlock();
}
}
11 changes: 2 additions & 9 deletions common/graphicsviewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,13 @@ class GraphicViewPortClass
void Remap(int sx, int sy, int width, int height, void* remap);
void Remap(void* remap);
void Draw_Stamp(void const* icondata, int icon, int x_pixel, int y_pixel, void const* remap, int clip_window);

// PG_TO_FIX
// This seems to be missing. Might not be needed anyway since it looks like it's only used for UI drawing. ST -
// 12/17/2018 6:11PM
void Texture_Fill_Rect(int xpos,
int ypos,
int width,
int height,
void const* shape_pointer,
unsigned char* shape_pointer,
int source_width,
int source_height)
{
return;
}
int source_height);

// This doesnt seem to exist anywhere?? - Steve T 9/26/95 6:05PM
// VOID Grey_Out_Region(int x, int y, int width, int height, int color);
Expand Down
6 changes: 3 additions & 3 deletions common/mixfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ template <class T, class TCRC> bool MixFileClass<T, TCRC>::Cache(Buffer const* b
*/
int actual = straw->Get(Data, DataSize);
if (actual != DataSize) {
delete[] Data;
delete[] static_cast<char*>(Data);
Data = NULL;
file.Error(EIO);
return (false);
Expand All @@ -670,7 +670,7 @@ template <class T, class TCRC> bool MixFileClass<T, TCRC>::Cache(Buffer const* b
sha.Result(digest2);
fstraw.Get(digest1, sizeof(digest1));
if (memcmp(digest1, digest2, sizeof(digest1)) != 0) {
delete[] Data;
delete[] static_cast<char*>(Data);
Data = NULL;
return (false);
}
Expand Down Expand Up @@ -702,7 +702,7 @@ template <class T, class TCRC> bool MixFileClass<T, TCRC>::Cache(Buffer const* b
template <class T, class TCRC> void MixFileClass<T, TCRC>::Free(void)
{
if (Data != NULL && IsAllocated) {
delete[] Data;
delete[] static_cast<char*>(Data);
}
Data = NULL;
IsAllocated = false;
Expand Down
Loading

0 comments on commit 9572d10

Please sign in to comment.